Allow page id references with section
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user