import Foundation struct IndexPageGenerator { private let factory: LocalizedSiteTemplate init(factory: LocalizedSiteTemplate) { self.factory = factory } func generate(site: Element, language: String) { let localized = site.localized(for: language) let path = site.localizedPath(for: language) let pageUrl = files.urlInOutputFolder(path) let languageButton = site.nextLanguage(for: language) let sectionItemCount = site.overviewItemCount 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: pageUrl) else { return } files.generated(page: 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) } }