CHGenerator/WebsiteGenerator/Generators/OverviewPageGenerator.swift

53 lines
2.0 KiB
Swift
Raw Normal View History

2022-08-16 10:39:05 +02:00
import Foundation
struct OverviewPageGenerator {
private let factory: LocalizedSiteTemplate
init(factory: LocalizedSiteTemplate) {
2022-08-16 10:39:05 +02:00
self.factory = factory
}
func generate(
section: Element,
2022-08-26 22:30:10 +02:00
language: String) {
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-16 12:27:13 +02:00
var content = [PageTemplate.Key : String]()
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(
sectionUrl: section.sectionUrl(for: language),
2022-09-04 17:47:13 +02:00
languageButton: languageButton,
page: section)
2022-08-16 12:27:13 +02:00
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
}
2022-09-02 23:19:13 +02:00
files.generated(page: path)
2022-08-16 10:39:05 +02:00
}
private func makeContent(section: Element, language: String) -> String {
2022-08-16 10:39:05 +02:00
if section.hasNestingElements {
return factory.overviewSection.generate(
2022-08-28 11:15:36 +02:00
sections: section.sortedItems,
2022-08-16 10:39:05 +02:00
in: section,
language: language,
sectionItemCount: section.overviewItemCount)
2022-08-16 10:39:05 +02:00
} else {
return factory.overviewSection.generate(section: section, language: language)
2022-08-16 10:39:05 +02:00
}
}
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language)
2022-08-16 12:27:13 +02:00
return factory.factory.centeredHeader.generate(content)
}
2022-08-16 10:39:05 +02:00
}