Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
d78127dc
Commit
d78127dc
authored
Oct 31, 2019
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: handle link reformatting when not using namespacing + 5 letters locales support (#1165, #1166)
parent
76b97e9f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
15 deletions
+44
-15
renderer.js
server/modules/rendering/html-core/renderer.js
+44
-15
No files found.
server/modules/rendering/html-core/renderer.js
View file @
d78127dc
const
_
=
require
(
'lodash'
)
const
cheerio
=
require
(
'cheerio'
)
const
uslug
=
require
(
'uslug'
)
const
pageHelper
=
require
(
'../../../helpers/page'
)
const
URL
=
require
(
'url'
).
URL
/* global WIKI */
...
...
@@ -23,6 +25,7 @@ module.exports = {
let
internalRefs
=
[]
const
reservedPrefixes
=
/^
\/[
a-z
]\/
/gi
const
exactReservedPaths
=
/^
\/[
a-z
]
$/gi
const
isHostSet
=
WIKI
.
config
.
host
.
length
>
7
&&
WIKI
.
config
.
host
!==
'http://'
if
(
!
isHostSet
)
{
...
...
@@ -50,21 +53,44 @@ module.exports = {
}
// -> Check for system prefix
if
(
!
reservedPrefixes
.
test
(
href
))
{
$
(
elm
).
addClass
(
`is-internal-link`
)
// -> Reformat paths
if
(
href
.
indexOf
(
'/'
)
!==
0
)
{
href
=
`/
${
this
.
page
.
localeCode
}
/
${
this
.
page
.
path
}
/
${
href
}
`
}
else
if
(
href
.
charAt
(
3
)
!==
'/'
)
{
href
=
`/
${
this
.
page
.
localeCode
}${
href
}
`
if
(
!
reservedPrefixes
.
test
(
href
)
&&
!
exactReservedPaths
.
test
(
href
))
{
let
pagePath
=
null
// -> Add locale prefix if using namespacing
if
(
WIKI
.
config
.
lang
.
namespacing
)
{
// -> Reformat paths
if
(
href
.
indexOf
(
'/'
)
!==
0
)
{
href
=
`/
${
this
.
page
.
localeCode
}
/
${
this
.
page
.
path
}
/
${
href
}
`
}
else
if
(
href
.
charAt
(
3
)
!==
'/'
)
{
href
=
`/
${
this
.
page
.
localeCode
}${
href
}
`
}
try
{
const
parsedUrl
=
new
URL
(
`http://x
${
href
}
`
)
pagePath
=
pageHelper
.
parsePath
(
parsedUrl
.
pathname
)
}
catch
(
err
)
{
return
}
}
else
{
// -> Reformat paths
if
(
href
.
indexOf
(
'/'
)
!==
0
)
{
href
=
`/
${
this
.
page
.
path
}
/
${
href
}
`
}
try
{
const
parsedUrl
=
new
URL
(
`http://x
${
href
}
`
)
pagePath
=
pageHelper
.
parsePath
(
parsedUrl
.
pathname
)
}
catch
(
err
)
{
return
}
}
// -> Save internal references
internalRefs
.
push
({
localeCode
:
href
.
substring
(
1
,
3
)
,
path
:
_
.
head
(
href
.
substring
(
4
).
split
(
'#'
))
localeCode
:
pagePath
.
locale
,
path
:
pagePath
.
path
})
$
(
elm
).
addClass
(
`is-internal-link`
)
}
else
{
$
(
elm
).
addClass
(
`is-system-link`
)
}
...
...
@@ -97,12 +123,15 @@ module.exports = {
// -> Apply tag to internal links for found pages
$
(
'a.is-internal-link'
).
each
((
i
,
elm
)
=>
{
const
href
=
$
(
elm
).
attr
(
'href'
)
const
hrefObj
=
{
localeCode
:
href
.
substring
(
1
,
3
),
path
:
_
.
head
(
href
.
substring
(
4
).
split
(
'#'
))
let
hrefObj
=
{}
try
{
const
parsedUrl
=
new
URL
(
`http://x
${
href
}
`
)
hrefObj
=
pageHelper
.
parsePath
(
parsedUrl
.
pathname
)
}
catch
(
err
)
{
return
}
if
(
_
.
some
(
results
,
r
=>
{
return
r
.
localeCode
===
hrefObj
.
locale
Code
&&
r
.
path
===
hrefObj
.
path
return
r
.
localeCode
===
hrefObj
.
locale
&&
r
.
path
===
hrefObj
.
path
}))
{
$
(
elm
).
addClass
(
`is-valid-page`
)
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment