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(page: site, metadata: localized, language: language) content[.content] = factory.overviewSection.generate( sections: site.sortedItems, 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(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String { let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language) return factory.factory.centeredHeader.generate(content) } }