Allow page id references with section
This commit is contained in:
parent
bd57c6fbf5
commit
2608e870cc
@ -56,6 +56,11 @@ extension String {
|
|||||||
return parts.dropLast().joined(separator: separator) + content + separator + parts.last!
|
return parts.dropLast().joined(separator: separator) + content + separator + parts.last!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Remove everything behind the first separator.
|
||||||
|
|
||||||
|
Also removes the separator itself. If the separator is not contained in the string, then the full string is returned.
|
||||||
|
*/
|
||||||
func dropAfterFirst<T>(_ separator: T) -> String where T: StringProtocol {
|
func dropAfterFirst<T>(_ separator: T) -> String where T: StringProtocol {
|
||||||
components(separatedBy: separator).first!
|
components(separatedBy: separator).first!
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import Splash
|
|||||||
|
|
||||||
struct PageContentGenerator {
|
struct PageContentGenerator {
|
||||||
|
|
||||||
|
private let pageLinkMarker = "page:"
|
||||||
|
|
||||||
private let largeImageIndicator = "*large*"
|
private let largeImageIndicator = "*large*"
|
||||||
|
|
||||||
private let factory: TemplateFactory
|
private let factory: TemplateFactory
|
||||||
@ -51,15 +53,16 @@ struct PageContentGenerator {
|
|||||||
|
|
||||||
private func handleLink(page: Element, language: String, html: String, markdown: Substring) -> String {
|
private func handleLink(page: Element, language: String, html: String, markdown: Substring) -> String {
|
||||||
let file = markdown.between("(", and: ")")
|
let file = markdown.between("(", and: ")")
|
||||||
if file.hasPrefix("page:") {
|
if file.hasPrefix(pageLinkMarker) {
|
||||||
let pageId = file.replacingOccurrences(of: "page:", with: "")
|
let textToChange = file.dropAfterFirst("#")
|
||||||
|
let pageId = textToChange.replacingOccurrences(of: pageLinkMarker, with: "")
|
||||||
guard let pagePath = results.getPagePath(for: pageId, source: page.path, language: language) else {
|
guard let pagePath = results.getPagePath(for: pageId, source: page.path, language: language) else {
|
||||||
// Remove link since the page can't be found
|
// Remove link since the page can't be found
|
||||||
return markdown.between("[", and: "]")
|
return markdown.between("[", and: "]")
|
||||||
}
|
}
|
||||||
// Adjust file path to get the page url
|
// Adjust file path to get the page url
|
||||||
let url = page.relativePathToOtherSiteElement(file: pagePath)
|
let url = page.relativePathToOtherSiteElement(file: pagePath)
|
||||||
return html.replacingOccurrences(of: file, with: url)
|
return html.replacingOccurrences(of: textToChange, with: url)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let filePath = page.nonAbsolutePathRelativeToRootForContainedInputFile(file) {
|
if let filePath = page.nonAbsolutePathRelativeToRootForContainedInputFile(file) {
|
||||||
|
Loading…
Reference in New Issue
Block a user