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) } }