52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
import Foundation
|
|
|
|
struct SiteGenerator {
|
|
|
|
let templates: TemplateFactory
|
|
|
|
init() throws {
|
|
let templatesFolder = files.urlInContentFolder("templates")
|
|
self.templates = try TemplateFactory(templateFolder: templatesFolder)
|
|
}
|
|
|
|
func generate(site: Element) throws {
|
|
site.requiredFiles.forEach(files.require)
|
|
site.externalFiles.forEach(files.exclude)
|
|
try site.languages.forEach {
|
|
try generate(site: site, metadata: $0)
|
|
}
|
|
}
|
|
|
|
private func generate(site: Element, metadata: Element.LocalizedMetadata) throws {
|
|
let language = metadata.language
|
|
let template = try LocalizedSiteTemplate(
|
|
factory: templates,
|
|
language: language,
|
|
site: site)
|
|
|
|
// Generate sections
|
|
let overviewGenerator = OverviewPageGenerator(factory: template)
|
|
let pageGenerator = PageGenerator(factory: template)
|
|
|
|
var elementsToProcess: [Element] = [site]
|
|
while let element = elementsToProcess.popLast() {
|
|
// Move recursively down to all pages
|
|
elementsToProcess.append(contentsOf: element.elements)
|
|
|
|
element.requiredFiles.forEach(files.require)
|
|
element.externalFiles.forEach(files.exclude)
|
|
|
|
if !element.elements.isEmpty {
|
|
overviewGenerator.generate(section: element, language: language)
|
|
} else {
|
|
#warning("Determine previous and next pages (with relative links)")
|
|
pageGenerator.generate(
|
|
page: element,
|
|
language: language,
|
|
nextPage: nil,
|
|
previousPage: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|