2022-08-16 10:39:05 +02:00
|
|
|
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
|
|
|
|
|
2022-08-16 12:26:45 +02:00
|
|
|
init(factory: LocalizedSiteTemplate) {
|
2022-08-16 10:39:05 +02:00
|
|
|
self.factory = factory
|
|
|
|
}
|
|
|
|
|
|
|
|
func generate(
|
|
|
|
site: Site,
|
|
|
|
language: String,
|
|
|
|
languageButton: String?,
|
|
|
|
sectionItemCount: Int,
|
|
|
|
to url: URL) throws {
|
|
|
|
let localized = site.localized(for: language)
|
|
|
|
|
2022-08-16 12:27:13 +02:00
|
|
|
var content = [PageTemplate.Key : String]()
|
2022-08-16 10:39:05 +02:00
|
|
|
content[.head] = try makeHead(site: site, language: language)
|
|
|
|
content[.topBar] = factory.topBar.generate(section: nil, languageButton: languageButton)
|
2022-08-16 12:27:13 +02:00
|
|
|
content[.contentClass] = "overview"
|
|
|
|
content[.header] = makeHeader(localized: localized)
|
2022-08-16 10:39:05 +02:00
|
|
|
let sections = site.elements.compactMap { $0 as? Section }
|
2022-08-16 12:27:13 +02:00
|
|
|
content[.content] = try factory.overviewSection.generate(
|
2022-08-16 10:39:05 +02:00
|
|
|
sections: sections,
|
|
|
|
in: site,
|
|
|
|
language: language,
|
|
|
|
sectionItemCount: sectionItemCount)
|
|
|
|
content[.footer] = SiteGenerator.pageFooter
|
2022-08-16 12:27:13 +02:00
|
|
|
try factory.page.generate(content, to: url)
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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()))
|
|
|
|
}
|
2022-08-16 12:27:13 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2022-08-16 10:39:05 +02:00
|
|
|
}
|