52 lines
2.0 KiB
Swift
52 lines
2.0 KiB
Swift
import Foundation
|
|
|
|
struct OverviewPageGenerator {
|
|
|
|
private let factory: LocalizedSiteTemplate
|
|
|
|
init(factory: LocalizedSiteTemplate) {
|
|
self.factory = factory
|
|
}
|
|
|
|
func generate(
|
|
section: Element,
|
|
language: String) {
|
|
let path = section.localizedPath(for: language)
|
|
let url = files.urlInOutputFolder(path)
|
|
|
|
let metadata = section.localized(for: language)
|
|
|
|
var content = [PageTemplate.Key : String]()
|
|
content[.head] = factory.pageHead.generate(page: section, language: language)
|
|
let languageButton = section.nextLanguage(for: language)
|
|
content[.topBar] = factory.topBar.generate(
|
|
sectionUrl: section.sectionUrl(for: language),
|
|
languageButton: languageButton)
|
|
content[.contentClass] = "overview"
|
|
content[.header] = makeHeader(page: section, metadata: metadata, language: language)
|
|
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)
|
|
}
|
|
|
|
private func makeContent(section: Element, language: String) -> String {
|
|
if section.hasNestingElements {
|
|
return factory.overviewSection.generate(
|
|
sections: section.sortedItems,
|
|
in: section,
|
|
language: language,
|
|
sectionItemCount: section.overviewItemCount)
|
|
} else {
|
|
return factory.overviewSection.generate(section: section, language: language)
|
|
}
|
|
}
|
|
|
|
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
|
|
let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language)
|
|
return factory.factory.centeredHeader.generate(content)
|
|
}
|
|
}
|