CHGenerator/WebsiteGenerator/Generators/IndexPageGenerator.swift

41 lines
1.5 KiB
Swift
Raw Normal View History

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(
site: Element,
2022-08-16 10:39:05 +02:00
language: String,
languageButton: String?,
sectionItemCount: Int,
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]()
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"
content[.header] = makeHeader(page: site, metadata: localized, language: language)
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)
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
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
}