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!
|
||||
}
|
||||
|
||||
/**
|
||||
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 {
|
||||
components(separatedBy: separator).first!
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import Splash
|
||||
|
||||
struct PageContentGenerator {
|
||||
|
||||
private let pageLinkMarker = "page:"
|
||||
|
||||
private let largeImageIndicator = "*large*"
|
||||
|
||||
private let factory: TemplateFactory
|
||||
@ -51,15 +53,16 @@ struct PageContentGenerator {
|
||||
|
||||
private func handleLink(page: Element, language: String, html: String, markdown: Substring) -> String {
|
||||
let file = markdown.between("(", and: ")")
|
||||
if file.hasPrefix("page:") {
|
||||
let pageId = file.replacingOccurrences(of: "page:", with: "")
|
||||
if file.hasPrefix(pageLinkMarker) {
|
||||
let textToChange = file.dropAfterFirst("#")
|
||||
let pageId = textToChange.replacingOccurrences(of: pageLinkMarker, with: "")
|
||||
guard let pagePath = results.getPagePath(for: pageId, source: page.path, language: language) else {
|
||||
// Remove link since the page can't be found
|
||||
return markdown.between("[", and: "]")
|
||||
}
|
||||
// Adjust file path to get the page url
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user