2022-08-16 10:39:05 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct IndexPageGenerator {
|
|
|
|
|
|
|
|
private let factory: LocalizedSiteTemplate
|
|
|
|
|
2022-08-16 12:26:45 +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
|
|
|
site: Element,
|
2022-08-16 10:39:05 +02:00
|
|
|
language: String,
|
|
|
|
languageButton: String?,
|
|
|
|
sectionItemCount: Int,
|
2022-08-26 17:40:51 +02:00
|
|
|
to url: URL) {
|
2022-08-16 10:39:05 +02:00
|
|
|
let localized = site.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: site, language: language)
|
|
|
|
content[.topBar] = factory.topBar.generate(sectionUrl: nil, languageButton: languageButton)
|
2022-08-16 12:27:13 +02:00
|
|
|
content[.contentClass] = "overview"
|
2022-08-28 11:14:11 +02:00
|
|
|
content[.header] = makeHeader(page: site, metadata: localized, language: language)
|
2022-08-26 17:40:51 +02:00
|
|
|
content[.content] = factory.overviewSection.generate(
|
2022-08-28 11:15:36 +02:00
|
|
|
sections: site.sortedItems,
|
2022-08-16 10:39:05 +02:00
|
|
|
in: site,
|
|
|
|
language: language,
|
|
|
|
sectionItemCount: sectionItemCount)
|
2022-08-26 17:40:51 +02:00
|
|
|
content[.footer] = site.customFooterContent()
|
|
|
|
guard factory.page.generate(content, to: url) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.add(info: "Generated \(url.lastPathComponent)", source: site.path)
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|
2022-08-16 12:27:13 +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
|
|
|
}
|