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()) private let swift = SyntaxHighlighter(format: HTMLOutputFormat())
init(factory: TemplateFactory) { private let siteRoot: Element
init(factory: TemplateFactory, siteRoot: Element) {
self.factory = factory self.factory = factory
self.siteRoot = siteRoot
} }
func generate(page: Element, language: String, content: String) -> (content: String, includesCode: Bool) { func generate(page: Element, language: String, content: String) -> (content: String, includesCode: Bool) {

View File

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

View File

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

View File

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