2022-08-16 10:39:05 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct OverviewPageGenerator {
|
|
|
|
|
|
|
|
private let factory: LocalizedSiteTemplate
|
|
|
|
|
2022-08-26 17:40:51 +02:00
|
|
|
init(factory: LocalizedSiteTemplate) {
|
2022-08-16 10:39:05 +02:00
|
|
|
self.factory = factory
|
|
|
|
}
|
|
|
|
|
|
|
|
func generate(
|
2022-08-26 17:40:51 +02:00
|
|
|
section: Element,
|
2022-08-26 22:30:10 +02:00
|
|
|
language: String) {
|
2022-08-26 17:40:51 +02:00
|
|
|
let path = section.localizedPath(for: language)
|
|
|
|
let url = files.urlInOutputFolder(path)
|
2022-08-16 10:39:05 +02:00
|
|
|
|
|
|
|
let metadata = section.localized(for: language)
|
2022-08-26 22:30:10 +02:00
|
|
|
let backLinkText = section.backLinkText(for: language)
|
2022-08-16 10:39:05 +02:00
|
|
|
|
2022-08-16 12:27:13 +02:00
|
|
|
var content = [PageTemplate.Key : String]()
|
2022-08-26 17:40:51 +02:00
|
|
|
content[.head] = factory.pageHead.generate(page: section, language: language)
|
2022-08-16 10:39:05 +02:00
|
|
|
let languageButton = section.nextLanguage(for: language)
|
|
|
|
content[.topBar] = factory.topBar.generate(
|
2022-08-26 17:40:51 +02:00
|
|
|
sectionUrl: section.sectionUrl(for: language),
|
2022-08-16 10:39:05 +02:00
|
|
|
languageButton: languageButton)
|
2022-08-16 12:27:13 +02:00
|
|
|
content[.contentClass] = "overview"
|
2022-08-26 22:30:10 +02:00
|
|
|
content[.header] = makeHeader(metadata: metadata, language: language, backText: backLinkText)
|
2022-08-26 17:40:51 +02:00
|
|
|
content[.content] = makeContent(section: section, language: language)
|
|
|
|
content[.footer] = section.customFooterContent()
|
|
|
|
guard factory.page.generate(content, to: url) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.add(info: "Generated \(path)", source: section.path)
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-26 17:40:51 +02:00
|
|
|
private func makeContent(section: Element, language: String) -> String {
|
2022-08-16 10:39:05 +02:00
|
|
|
if section.hasNestingElements {
|
2022-08-26 17:40:51 +02:00
|
|
|
return factory.overviewSection.generate(
|
|
|
|
sections: section.elements,
|
2022-08-16 10:39:05 +02:00
|
|
|
in: section,
|
|
|
|
language: language,
|
2022-08-26 17:40:51 +02:00
|
|
|
sectionItemCount: section.overviewItemCount)
|
2022-08-16 10:39:05 +02:00
|
|
|
} else {
|
2022-08-26 17:40:51 +02:00
|
|
|
return factory.overviewSection.generate(section: section, language: language)
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-26 17:40:51 +02:00
|
|
|
private func makeHeader(metadata: Element.LocalizedMetadata,
|
2022-08-16 12:27:13 +02:00
|
|
|
language: String,
|
|
|
|
backText: String?) -> String {
|
|
|
|
var content = [HeaderKey : String]()
|
|
|
|
content[.title] = metadata.title
|
2022-08-26 17:40:51 +02:00
|
|
|
#warning("Add title suffix")
|
2022-08-16 12:27:13 +02:00
|
|
|
content[.subtitle] = metadata.subtitle
|
|
|
|
content[.titleText] = metadata.description
|
|
|
|
content[.backLink] = backText.unwrapped { factory.makeBackLink(text: $0, language: language) }
|
|
|
|
return factory.factory.centeredHeader.generate(content)
|
|
|
|
}
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|