Simplify code for back link texts
This commit is contained in:
parent
fff62f4b44
commit
8da6bf35d5
@ -10,12 +10,12 @@ struct OverviewPageGenerator {
|
||||
|
||||
func generate(
|
||||
section: Element,
|
||||
language: String,
|
||||
backText: String?) {
|
||||
language: String) {
|
||||
let path = section.localizedPath(for: language)
|
||||
let url = files.urlInOutputFolder(path)
|
||||
|
||||
let metadata = section.localized(for: language)
|
||||
let backLinkText = section.backLinkText(for: language)
|
||||
|
||||
var content = [PageTemplate.Key : String]()
|
||||
content[.head] = factory.pageHead.generate(page: section, language: language)
|
||||
@ -24,7 +24,7 @@ struct OverviewPageGenerator {
|
||||
sectionUrl: section.sectionUrl(for: language),
|
||||
languageButton: languageButton)
|
||||
content[.contentClass] = "overview"
|
||||
content[.header] = makeHeader(metadata: metadata, language: language, backText: backText)
|
||||
content[.header] = makeHeader(metadata: metadata, language: language, backText: backLinkText)
|
||||
content[.content] = makeContent(section: section, language: language)
|
||||
content[.footer] = section.customFooterContent()
|
||||
guard factory.page.generate(content, to: url) else {
|
||||
|
@ -16,7 +16,7 @@ struct PageGenerator {
|
||||
self.factory = factory
|
||||
}
|
||||
|
||||
func generate(page: Element, language: String, backText: String, nextPage: NavigationLink?, previousPage: NavigationLink?) {
|
||||
func generate(page: Element, language: String, nextPage: NavigationLink?, previousPage: NavigationLink?) {
|
||||
guard !page.isExternalPage else {
|
||||
return
|
||||
}
|
||||
@ -28,13 +28,14 @@ struct PageGenerator {
|
||||
#warning("Make prev and next navigation relative")
|
||||
let metadata = page.localized(for: language)
|
||||
let nextLanguage = page.nextLanguage(for: language)
|
||||
|
||||
var content = [PageTemplate.Key : String]()
|
||||
content[.head] = factory.pageHead.generate(page: page, language: language)
|
||||
let sectionUrl = page.sectionUrl(for: language)
|
||||
content[.topBar] = factory.topBar.generate(sectionUrl: sectionUrl, languageButton: nextLanguage)
|
||||
content[.contentClass] = "content"
|
||||
if !page.useCustomHeader {
|
||||
content[.header] = makeHeader(page: page, metadata: metadata, language: language, backText: backText)
|
||||
content[.header] = makeHeader(page: page, metadata: metadata, language: language)
|
||||
}
|
||||
let pageContent = makeContent(page: page, language: language, path: inputContentPath)
|
||||
content[.content] = pageContent ?? factory.placeholder
|
||||
@ -59,7 +60,9 @@ struct PageGenerator {
|
||||
.generate(page: page, language: language, content: content)
|
||||
}
|
||||
|
||||
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String, backText: String) -> String {
|
||||
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
|
||||
let backText = page.backLinkText(for: language)
|
||||
|
||||
var content = [HeaderKey : String]()
|
||||
content[.backLink] = factory.makeBackLink(text: backText, language: language)
|
||||
if let suffix = metadata.titleSuffix {
|
||||
|
@ -27,18 +27,15 @@ struct SiteGenerator {
|
||||
|
||||
element.requiredFiles.forEach(files.require)
|
||||
|
||||
let backLinkText = element.backLinkText(for: language)
|
||||
if !element.elements.isEmpty {
|
||||
overviewGenerator.generate(
|
||||
section: element,
|
||||
language: language,
|
||||
backText: backLinkText)
|
||||
language: language)
|
||||
} else {
|
||||
#warning("Determine previous and next pages")
|
||||
pageGenerator.generate(
|
||||
page: element,
|
||||
language: language,
|
||||
backText: backLinkText,
|
||||
nextPage: nil,
|
||||
previousPage: nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user