CHGenerator/WebsiteGenerator/Generators/IndexPageGenerator.swift
Christoph Hagen 80d3c08a93 Update generation
- Move to global objects for files and validation
- Only write changed files
- Check images for changes before scaling
- Simplify code
2022-08-26 17:40:51 +02:00

45 lines
1.6 KiB
Swift

import Foundation
struct IndexPageGenerator {
private let factory: LocalizedSiteTemplate
init(factory: LocalizedSiteTemplate) {
self.factory = factory
}
func generate(
site: Element,
language: String,
languageButton: String?,
sectionItemCount: Int,
to url: URL) {
let localized = site.localized(for: language)
var content = [PageTemplate.Key : String]()
content[.head] = factory.pageHead.generate(page: site, language: language)
content[.topBar] = factory.topBar.generate(sectionUrl: nil, languageButton: languageButton)
content[.contentClass] = "overview"
content[.header] = makeHeader(localized: localized)
content[.content] = factory.overviewSection.generate(
sections: site.elements,
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)
}
private func makeHeader(localized: Element.LocalizedMetadata) -> String {
var content = [HeaderKey : String]()
content[.title] = localized.title
#warning("Add title suffix")
content[.subtitle] = localized.subtitle
content[.titleText] = localized.description
return factory.factory.centeredHeader.generate(content)
}
}