Remove global site root

This commit is contained in:
Christoph Hagen 2022-12-01 15:25:55 +01:00
parent 90d2573d0c
commit 92d832dc44
4 changed files with 12 additions and 10 deletions

View File

@ -8,8 +8,11 @@ struct PageContentGenerator {
private let swift = SyntaxHighlighter(format: HTMLOutputFormat())
init(factory: TemplateFactory) {
private let siteRoot: Element
init(factory: TemplateFactory, siteRoot: Element) {
self.factory = factory
self.siteRoot = siteRoot
}
func generate(page: Element, language: String, content: String) -> (content: String, includesCode: Bool) {

View File

@ -5,8 +5,11 @@ struct PageGenerator {
private let factory: LocalizedSiteTemplate
init(factory: LocalizedSiteTemplate) {
private let contentGenerator: PageContentGenerator
init(factory: LocalizedSiteTemplate, siteRoot: Element) {
self.factory = factory
self.contentGenerator = PageContentGenerator(factory: factory.factory, siteRoot: siteRoot)
}
func generate(page: Element, language: String, previousPage: Element?, nextPage: Element?) {
@ -74,12 +77,10 @@ struct PageGenerator {
private func makeContent(page: Element, metadata: Element.LocalizedMetadata, language: String, path: String) -> (content: String, includesCode: Bool, isEmpty: Bool) {
if let raw = files.contentOfMdFile(atPath: path, source: page.path)?.trimmed.nonEmpty {
let (content, includesCode) = PageContentGenerator(factory: factory.factory)
.generate(page: page, language: language, content: raw)
let (content, includesCode) = contentGenerator.generate(page: page, language: language, content: raw)
return (content, includesCode, false)
} else {
let (content, includesCode) = PageContentGenerator(factory: factory.factory)
.generate(page: page, language: language, content: metadata.placeholderText)
let (content, includesCode) = contentGenerator.generate(page: page, language: language, content: metadata.placeholderText)
let placeholder = factory.factory.makePlaceholder(title: metadata.placeholderTitle, text: content)
return (placeholder, includesCode, true)
}

View File

@ -26,7 +26,7 @@ struct SiteGenerator {
// Generate sections
let overviewGenerator = OverviewPageGenerator(factory: template)
let pageGenerator = PageGenerator(factory: template)
let pageGenerator = PageGenerator(factory: template, siteRoot: site)
var elementsToProcess: [LinkedElement] = [(nil, site, nil)]
while let (previous, element, next) = elementsToProcess.popLast() {

View File

@ -3,7 +3,6 @@ import ArgumentParser
let log = ValidationLog()
var files: FileSystem!
var siteRoot: Element!
@main
struct CHGenerator: ParsableCommand {
@ -57,8 +56,7 @@ private func generate(configPath: String) throws {
// 2. Scan site elements
siteRoot = try loadSiteData(in: configuration.contentDirectory)
guard siteRoot != nil else {
guard let siteRoot = try loadSiteData(in: configuration.contentDirectory) else {
return
}
let siteGenerator = try SiteGenerator()