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