Fix links to external pages

This commit is contained in:
Christoph Hagen
2022-12-05 17:25:07 +01:00
parent 464ece4a03
commit deb7e6187e
4 changed files with 36 additions and 25 deletions

View File

@ -47,13 +47,12 @@ struct PageContentGenerator {
let file = markdown.between("(", and: ")")
if file.hasPrefix("page:") {
let pageId = file.replacingOccurrences(of: "page:", with: "")
guard let pagePath = results.getPagePath(for: pageId, source: page.path) else {
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: "]")
}
let fullPath = pagePath + Element.htmlPagePathAddition(for: language)
// Adjust file path to get the page url
let url = page.relativePathToOtherSiteElement(file: fullPath)
let url = page.relativePathToOtherSiteElement(file: pagePath)
return html.replacingOccurrences(of: file, with: url)
}
@ -244,7 +243,7 @@ struct PageContentGenerator {
private func handlePageLink(page: Element, language: String, pageId: String) -> String {
guard let linkedPage = siteRoot.find(pageId) else {
// Checking the page path will add it to the missing pages
_ = results.getPagePath(for: pageId, source: page.path)
_ = results.getPagePath(for: pageId, source: page.path, language: language)
// Remove link since the page can't be found
return ""
}