import Foundation struct OverviewPageGenerator { private let factory: LocalizedSiteTemplate init(factory: LocalizedSiteTemplate) { self.factory = factory } func generate( section: Element, language: String) { let path = section.localizedPath(for: language) let url = files.urlInOutputFolder(path) let metadata = section.localized(for: language) let backLinkText = section.backLinkText(for: language) var content = [PageTemplate.Key : String]() content[.head] = factory.pageHead.generate(page: section, language: language) let languageButton = section.nextLanguage(for: language) content[.topBar] = factory.topBar.generate( sectionUrl: section.sectionUrl(for: language), languageButton: languageButton) content[.contentClass] = "overview" content[.header] = makeHeader(metadata: metadata, language: language, backText: backLinkText) content[.content] = makeContent(section: section, language: language) content[.footer] = section.customFooterContent() guard factory.page.generate(content, to: url) else { return } log.add(info: "Generated \(path)", source: section.path) } private func makeContent(section: Element, language: String) -> String { if section.hasNestingElements { return factory.overviewSection.generate( sections: section.elements, in: section, language: language, sectionItemCount: section.overviewItemCount) } else { return factory.overviewSection.generate(section: section, language: language) } } private func makeHeader(metadata: Element.LocalizedMetadata, language: String, backText: String?) -> String { var content = [HeaderKey : String]() content[.title] = metadata.title #warning("Add title suffix") content[.subtitle] = metadata.subtitle content[.titleText] = metadata.description content[.backLink] = backText.unwrapped { factory.makeBackLink(text: $0, language: language) } return factory.factory.centeredHeader.generate(content) } }