2022-08-16 10:39:05 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct OverviewPageGenerator {
|
|
|
|
|
|
|
|
private let factory: LocalizedSiteTemplate
|
|
|
|
|
2022-12-04 19:15:22 +01:00
|
|
|
private let results: GenerationResultsHandler
|
|
|
|
|
|
|
|
init(factory: LocalizedSiteTemplate, results: GenerationResultsHandler) {
|
2022-08-16 10:39:05 +02:00
|
|
|
self.factory = factory
|
2022-12-04 19:15:22 +01:00
|
|
|
self.results = results
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
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]()
|
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-09-04 17:47:13 +02:00
|
|
|
languageButton: languageButton,
|
|
|
|
page: section)
|
2022-12-20 12:49:21 +01:00
|
|
|
content[.language] = language
|
2022-08-16 12:27:13 +02:00
|
|
|
content[.contentClass] = "overview"
|
2022-08-28 11:14:11 +02:00
|
|
|
content[.header] = makeHeader(page: section, metadata: metadata, language: language)
|
2022-08-26 17:40:51 +02:00
|
|
|
content[.content] = makeContent(section: section, language: language)
|
2022-12-04 19:15:22 +01:00
|
|
|
content[.footer] = results.getContentOfOptionalFile(at: section.additionalFooterContentPath, source: section.path)
|
|
|
|
factory.page.generate(content, to: 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(
|
2022-08-28 11:15:36 +02:00
|
|
|
sections: section.sortedItems,
|
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-28 11:14:11 +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
|
|
|
}
|