CHGenerator/WebsiteGenerator/Generators/IndexPageGenerator.swift

40 lines
1.5 KiB
Swift
Raw Normal View History

2022-08-16 10:39:05 +02:00
import Foundation
struct IndexPageGenerator {
private let factory: LocalizedSiteTemplate
2022-08-16 12:26:45 +02:00
init(factory: LocalizedSiteTemplate) {
2022-08-16 10:39:05 +02:00
self.factory = factory
}
2022-08-30 11:30:23 +02:00
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
2022-08-16 10:39:05 +02:00
2022-08-30 11:30:23 +02:00
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
}
log.add(info: "Page generated", source: path)
2022-08-16 10:39:05 +02:00
}
2022-08-16 12:27:13 +02:00
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language)
2022-08-16 12:27:13 +02:00
return factory.factory.centeredHeader.generate(content)
}
2022-08-16 10:39:05 +02:00
}