diff --git a/WebsiteGenerator/Content/Element.swift b/WebsiteGenerator/Content/Element.swift index d91ceac..aa8ed95 100644 --- a/WebsiteGenerator/Content/Element.swift +++ b/WebsiteGenerator/Content/Element.swift @@ -325,6 +325,17 @@ extension Element { + pageParts.dropFirst(index) 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. diff --git a/WebsiteGenerator/Generators/HTMLElementsGenerator.swift b/WebsiteGenerator/Generators/HTMLElementsGenerator.swift index 132c918..924e27f 100644 --- a/WebsiteGenerator/Generators/HTMLElementsGenerator.swift +++ b/WebsiteGenerator/Generators/HTMLElementsGenerator.swift @@ -10,9 +10,11 @@ struct HTMLElementsGenerator { "\(title)\(suffix)" } - // - TODO: Make link relative - func topBarWebsiteTitle(language: String) -> String { - Element.htmlPagePathAddition(for: language) + func topBarWebsiteTitle(language: String, from page: Element) -> String { + guard let pathToRoot = page.pathToRoot else { + return Element.htmlPageName(for: language) + } + return pathToRoot + Element.htmlPagePathAddition(for: language) } func topBarLanguageButton(_ language: String) -> String { diff --git a/WebsiteGenerator/Generators/OverviewPageGenerator.swift b/WebsiteGenerator/Generators/OverviewPageGenerator.swift index 955068e..47a5ca7 100644 --- a/WebsiteGenerator/Generators/OverviewPageGenerator.swift +++ b/WebsiteGenerator/Generators/OverviewPageGenerator.swift @@ -21,7 +21,8 @@ struct OverviewPageGenerator { let languageButton = section.nextLanguage(for: language) content[.topBar] = factory.topBar.generate( sectionUrl: section.sectionUrl(for: language), - languageButton: languageButton) + languageButton: languageButton, + page: section) content[.contentClass] = "overview" content[.header] = makeHeader(page: section, metadata: metadata, language: language) content[.content] = makeContent(section: section, language: language) diff --git a/WebsiteGenerator/Generators/PageGenerator.swift b/WebsiteGenerator/Generators/PageGenerator.swift index f2d89a5..fd6b828 100644 --- a/WebsiteGenerator/Generators/PageGenerator.swift +++ b/WebsiteGenerator/Generators/PageGenerator.swift @@ -30,7 +30,7 @@ struct PageGenerator { var content = [PageTemplate.Key : String]() content[.head] = factory.pageHead.generate(page: page, language: language, includesCode: pageIncludesCode) 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" if !page.useCustomHeader { diff --git a/WebsiteGenerator/Templates/Filled/PrefilledTopBarTemplate.swift b/WebsiteGenerator/Templates/Filled/PrefilledTopBarTemplate.swift index b487b24..6830559 100644 --- a/WebsiteGenerator/Templates/Filled/PrefilledTopBarTemplate.swift +++ b/WebsiteGenerator/Templates/Filled/PrefilledTopBarTemplate.swift @@ -17,10 +17,10 @@ struct PrefilledTopBarTemplate { self.topBarWebsiteTitle = topBarWebsiteTitle } - func generate(sectionUrl: String?, languageButton: String?) -> String { + func generate(sectionUrl: String?, languageButton: String?, page: Element) -> String { var content = [TopBarTemplate.Key : String]() 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[.languageButton] = languageButton.unwrapped(factory.html.topBarLanguageButton) ?? "" return factory.topBar.generate(content)