Make highlight script path relative
This commit is contained in:
parent
cec60e9ff2
commit
aa701d9793
@ -304,15 +304,15 @@ extension Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a relative link to another page in the tree.
|
Create a relative link to another file in the tree.
|
||||||
- Parameter pageUrl: The full page url of the target page, including localization
|
- Parameter file: The full path of the target file, including localization
|
||||||
- Returns: The relative url from a localized page of the element to the target page.
|
- Returns: The relative url from a localized page of the element to the target file.
|
||||||
*/
|
*/
|
||||||
func relativePathToOtherSiteElement(pageUrl: String) -> String {
|
func relativePathToOtherSiteElement(file: String) -> String {
|
||||||
// Note: The element `path` is missing the last component
|
// Note: The element `path` is missing the last component
|
||||||
// i.e. travel/alps instead of travel/alps/en.html
|
// i.e. travel/alps instead of travel/alps/en.html
|
||||||
let ownParts = path.components(separatedBy: "/")
|
let ownParts = path.components(separatedBy: "/")
|
||||||
let pageParts = pageUrl.components(separatedBy: "/")
|
let pageParts = file.components(separatedBy: "/")
|
||||||
|
|
||||||
// Find the common elements of the path, which can be discarded
|
// Find the common elements of the path, which can be discarded
|
||||||
var index = 0
|
var index = 0
|
||||||
|
@ -48,7 +48,7 @@ struct PageContentGenerator {
|
|||||||
}
|
}
|
||||||
let fullPath = pagePath + Element.htmlPagePathAddition(for: language)
|
let fullPath = pagePath + Element.htmlPagePathAddition(for: language)
|
||||||
// Adjust file path to get the page url
|
// Adjust file path to get the page url
|
||||||
let url = page.relativePathToOtherSiteElement(pageUrl: fullPath)
|
let url = page.relativePathToOtherSiteElement(file: fullPath)
|
||||||
return html.replacingOccurrences(of: file, with: url)
|
return html.replacingOccurrences(of: file, with: url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ struct PageHeadGenerator {
|
|||||||
}
|
}
|
||||||
content[.customPageContent] = page.customHeadContent()
|
content[.customPageContent] = page.customHeadContent()
|
||||||
if includesCode {
|
if includesCode {
|
||||||
let scriptPath = "/assets/js/highlight.js"
|
let scriptPath = "assets/js/highlight.js"
|
||||||
#warning("Make highlight script path relative")
|
let relative = page.relativePathToOtherSiteElement(file: scriptPath)
|
||||||
let includeText = factory.html.scriptInclude(path: scriptPath)
|
let includeText = factory.html.scriptInclude(path: relative)
|
||||||
if let head = content[.customPageContent] {
|
if let head = content[.customPageContent] {
|
||||||
content[.customPageContent] = head + "\n" + includeText
|
content[.customPageContent] = head + "\n" + includeText
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user