Make top bar link relative
This commit is contained in:
parent
9a40da63d3
commit
cec60e9ff2
@ -325,6 +325,17 @@ extension Element {
|
|||||||
+ pageParts.dropFirst(index)
|
+ pageParts.dropFirst(index)
|
||||||
return allParts.joined(separator: "/")
|
return allParts.joined(separator: "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The relative path to the site root.
|
||||||
|
*/
|
||||||
|
var pathToRoot: String? {
|
||||||
|
guard path != "" else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let downPathCount = path.components(separatedBy: "/").count
|
||||||
|
return [String](repeating: "..", count: downPathCount).joined(separator: "/")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create an absolute path (relative to the root directory) for a file contained in the elements folder.
|
Create an absolute path (relative to the root directory) for a file contained in the elements folder.
|
||||||
|
@ -10,9 +10,11 @@ struct HTMLElementsGenerator {
|
|||||||
"\(title)<span class=\"suffix\">\(suffix)</span>"
|
"\(title)<span class=\"suffix\">\(suffix)</span>"
|
||||||
}
|
}
|
||||||
|
|
||||||
// - TODO: Make link relative
|
func topBarWebsiteTitle(language: String, from page: Element) -> String {
|
||||||
func topBarWebsiteTitle(language: String) -> String {
|
guard let pathToRoot = page.pathToRoot else {
|
||||||
Element.htmlPagePathAddition(for: language)
|
return Element.htmlPageName(for: language)
|
||||||
|
}
|
||||||
|
return pathToRoot + Element.htmlPagePathAddition(for: language)
|
||||||
}
|
}
|
||||||
|
|
||||||
func topBarLanguageButton(_ language: String) -> String {
|
func topBarLanguageButton(_ language: String) -> String {
|
||||||
|
@ -21,7 +21,8 @@ struct OverviewPageGenerator {
|
|||||||
let languageButton = section.nextLanguage(for: language)
|
let languageButton = section.nextLanguage(for: language)
|
||||||
content[.topBar] = factory.topBar.generate(
|
content[.topBar] = factory.topBar.generate(
|
||||||
sectionUrl: section.sectionUrl(for: language),
|
sectionUrl: section.sectionUrl(for: language),
|
||||||
languageButton: languageButton)
|
languageButton: languageButton,
|
||||||
|
page: section)
|
||||||
content[.contentClass] = "overview"
|
content[.contentClass] = "overview"
|
||||||
content[.header] = makeHeader(page: section, metadata: metadata, language: language)
|
content[.header] = makeHeader(page: section, metadata: metadata, language: language)
|
||||||
content[.content] = makeContent(section: section, language: language)
|
content[.content] = makeContent(section: section, language: language)
|
||||||
|
@ -30,7 +30,7 @@ struct PageGenerator {
|
|||||||
var content = [PageTemplate.Key : String]()
|
var content = [PageTemplate.Key : String]()
|
||||||
content[.head] = factory.pageHead.generate(page: page, language: language, includesCode: pageIncludesCode)
|
content[.head] = factory.pageHead.generate(page: page, language: language, includesCode: pageIncludesCode)
|
||||||
let sectionUrl = page.sectionUrl(for: language)
|
let sectionUrl = page.sectionUrl(for: language)
|
||||||
content[.topBar] = factory.topBar.generate(sectionUrl: sectionUrl, languageButton: nextLanguage)
|
content[.topBar] = factory.topBar.generate(sectionUrl: sectionUrl, languageButton: nextLanguage, page: page)
|
||||||
content[.contentClass] = "content"
|
content[.contentClass] = "content"
|
||||||
|
|
||||||
if !page.useCustomHeader {
|
if !page.useCustomHeader {
|
||||||
|
@ -17,10 +17,10 @@ struct PrefilledTopBarTemplate {
|
|||||||
self.topBarWebsiteTitle = topBarWebsiteTitle
|
self.topBarWebsiteTitle = topBarWebsiteTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(sectionUrl: String?, languageButton: String?) -> String {
|
func generate(sectionUrl: String?, languageButton: String?, page: Element) -> String {
|
||||||
var content = [TopBarTemplate.Key : String]()
|
var content = [TopBarTemplate.Key : String]()
|
||||||
content[.title] = topBarWebsiteTitle
|
content[.title] = topBarWebsiteTitle
|
||||||
content[.titleLink] = factory.html.topBarWebsiteTitle(language: language)
|
content[.titleLink] = factory.html.topBarWebsiteTitle(language: language, from: page)
|
||||||
content[.elements] = elements(activeSectionUrl: sectionUrl)
|
content[.elements] = elements(activeSectionUrl: sectionUrl)
|
||||||
content[.languageButton] = languageButton.unwrapped(factory.html.topBarLanguageButton) ?? ""
|
content[.languageButton] = languageButton.unwrapped(factory.html.topBarLanguageButton) ?? ""
|
||||||
return factory.topBar.generate(content)
|
return factory.topBar.generate(content)
|
||||||
|
Loading…
Reference in New Issue
Block a user