diff --git a/Sources/ToucanSDK/Config/Config.swift b/Sources/ToucanSDK/Config/Config.swift index 8e1219c1..bc7f3e95 100644 --- a/Sources/ToucanSDK/Config/Config.swift +++ b/Sources/ToucanSDK/Config/Config.swift @@ -175,20 +175,20 @@ struct Config { } struct Pipeline { - + enum Keys { static let run = "run" static let render = "render" } - + struct Run { - + enum Keys { static let name = "name" } - + let name: String - + init?(_ dict: [String: Any]) { guard let name = dict.string(Keys.name) else { return nil @@ -196,12 +196,13 @@ struct Config { self.name = name } } - + let run: [Run] let render: Bool init(_ dict: [String: Any]) { - self.run = dict + self.run = + dict .array(Keys.run, as: [String: Any].self) .map { Run($0)! } self.render = dict.bool(Keys.render) ?? true @@ -223,7 +224,8 @@ struct Config { self.folder = dict.string(Location.Keys.folder) ?? Config.defaults.transformers.folder - self.pipelines = dict + self.pipelines = + dict .dict(Keys.pipelines) .compactMapValues { (item: Any) -> Pipeline? in guard let dict = item as? [String: Any] else { diff --git a/Sources/ToucanSDK/ContextStore/ContextStore.swift b/Sources/ToucanSDK/ContextStore/ContextStore.swift index 108331bc..ce089abe 100644 --- a/Sources/ToucanSDK/ContextStore/ContextStore.swift +++ b/Sources/ToucanSDK/ContextStore/ContextStore.swift @@ -117,18 +117,6 @@ struct ContextStore { self.markdownToCParser = .init() } - // func build() { - // for pageBundle in pageBundles { - // let ctx = standardContext(for: pageBundle) - // print("------------------------------------") - // print(pageBundle.slug) - // print(ctx.keys) - // if pageBundle.slug == "introducing-toucan-a-new-markdown-based-static-site-generator" { - // print(ctx["authors"]) - // } - // } - // } - private func baseContext( for pageBundle: PageBundle ) -> [String: Any] { @@ -156,11 +144,11 @@ struct ContextStore { pageBundle: pageBundle ) ) - + let pipelines = sourceConfig.config.transformers.pipelines let pipeline = pipelines[pageBundle.contentType.id] - var didRenderHTML = false - + let shouldRenderMarkdown = pipeline?.render ?? true + if let pipeline, !pipeline.run.isEmpty { let executor = PipelineExecutor( pipeline: pipeline, @@ -172,31 +160,25 @@ struct ContextStore { ) do { contents = try executor.execute() - didRenderHTML = true } catch { logger.error("\(String(describing: error))") } } - - if didRenderHTML { - let tocElements = htmlToCParser.parse(from: contents) ?? [] - return [ - "contents": contents, - "readingTime": contents.readingTime(), - "toc": tocElements.buildToCTree(), - ] + + let tocElements: [TocElement] + if shouldRenderMarkdown { + tocElements = markdownToCParser.parse(from: contents) ?? [] + contents = markdownRenderer.renderHTML(markdown: contents) } else { - let tocElements = markdownToCParser.parse(from: contents) ?? [] - let readingTime = contents.readingTime() - contents = markdownRenderer.renderHTML(markdown: contents) - return [ - "contents": contents, - "readingTime": readingTime, - "toc": tocElements.buildToCTree(), - ] + tocElements = htmlToCParser.parse(from: contents) ?? [] } + return [ + "contents": contents, + "readingTime": contents.readingTime(), + "toc": tocElements.buildToCTree(), + ] } private func relations( diff --git a/Sources/toucan-cli/Commands/Generate.swift b/Sources/toucan-cli/Commands/Generate.swift index b0e6a496..1b5dff5e 100644 --- a/Sources/toucan-cli/Commands/Generate.swift +++ b/Sources/toucan-cli/Commands/Generate.swift @@ -29,7 +29,7 @@ extension Entrypoint { baseUrl: baseUrl, logger: logger ) - + if generator.generateAndLogErrors(logger) { let metadata: Logger.Metadata = [ "input": "\(input)", diff --git a/Sources/toucan-cli/Commands/Watch.swift b/Sources/toucan-cli/Commands/Watch.swift index 91be6f32..e774306e 100644 --- a/Sources/toucan-cli/Commands/Watch.swift +++ b/Sources/toucan-cli/Commands/Watch.swift @@ -46,7 +46,7 @@ extension Entrypoint { logger: logger ) generator.generateAndLogErrors(logger) - + #if os(macOS) let eventStream = try EonilFSEventStream( pathsToWatch: [input], @@ -68,7 +68,8 @@ extension Entrypoint { logger.info("Generating site...") if generator.generateAndLogErrors(logger) { logger.info("Site re-generated.") - } else { + } + else { logger.info("Site generation failed.") } } diff --git a/Sources/toucan-cli/Extensions/Toucan+UserErrors.swift b/Sources/toucan-cli/Extensions/Toucan+UserErrors.swift index 79d381e6..e17fbac4 100644 --- a/Sources/toucan-cli/Extensions/Toucan+UserErrors.swift +++ b/Sources/toucan-cli/Extensions/Toucan+UserErrors.swift @@ -82,7 +82,7 @@ extension Toucan { catch { logger.error("\(String(describing: error))") } - + return false } }