import Foundation private struct AboveRootDummy: SiteElement { var sortIndex: Int? { nil } var sortDate: Date? { nil } var path: String { "" } let inputFolder: URL func title(for language: String) -> String { "" } func cornerText(for language: String) -> String? { nil } var elements: [SiteElement] { [] } } struct IndexPageGenerator { private let factory: LocalizedSiteTemplate init(factory: LocalizedSiteTemplate) { self.factory = factory } func generate( site: Site, language: String, languageButton: String?, sectionItemCount: Int, to url: URL) throws { let localized = site.localized(for: language) var content = [PageTemplate.Key : String]() content[.head] = try makeHead(site: site, language: language) content[.topBar] = factory.topBar.generate(section: nil, languageButton: languageButton) content[.contentClass] = "overview" content[.header] = makeHeader(localized: localized) let sections = site.elements.compactMap { $0 as? Section } content[.content] = try factory.overviewSection.generate( sections: sections, in: site, language: language, sectionItemCount: sectionItemCount) content[.footer] = try site.customFooterContent() try factory.page.generate(content, to: url) } private func makeHead(site: Site, language: String) throws -> String { let localized = site.localized(for: language) return try factory.pageHead.generate(page: PageHeadInfo( author: site.metadata.author, linkPreviewTitle: localized.linkPreviewTitle, linkPreviewDescription: localized.linkPreviewDescription, linkPreviewImage: site.linkPreviewImage(for: language), customHeadContent: try site.customHeadContent())) } private func makeHeader(localized: Site.LocalizedMetadata) -> String { var content = [HeaderKey : String]() content[.title] = localized.title content[.subtitle] = localized.subtitle content[.titleText] = localized.description return factory.factory.centeredHeader.generate(content) } }