Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contents support to RSS template #59

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions Sources/ToucanSDK/Renderers/RSSRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,42 @@
//

import Foundation
import Logging

struct RSSRenderer {

let sourceConfig: SourceConfig
let source: Source
let destinationUrl: URL
let fileManager: FileManager
let templateRenderer: MustacheToHTMLRenderer
let pageBundles: [PageBundle]
let logger: Logger

let contextStore: ContextStore

init(
source: Source,
destinationUrl: URL,
fileManager: FileManager,
templateRenderer: MustacheToHTMLRenderer,
pageBundles: [PageBundle],
logger: Logger
) {
self.source = source
self.destinationUrl = destinationUrl
self.fileManager = fileManager
self.templateRenderer = templateRenderer
self.pageBundles = pageBundles
self.logger = logger

self.contextStore = .init(
sourceConfig: source.sourceConfig,
contentTypes: source.contentTypes,
pageBundles: source.pageBundles,
blockDirectives: source.blockDirectives,
logger: logger
)
}

func render() throws {
guard !pageBundles.isEmpty else {
Expand All @@ -28,7 +56,7 @@ struct RSSRenderer {
title: item.title,
description: item.description,
publicationDate: item.date.rss,
userDefined: item.baseContext
userDefined: contextStore.fullContext(for: item)
)
}

Expand All @@ -39,22 +67,24 @@ struct RSSRenderer {
?? rssDateFormatter.string(from: .init())

let rssCtx = RSSContext(
title: sourceConfig.site.title,
description: sourceConfig.site.description,
baseUrl: sourceConfig.site.baseUrl,
language: sourceConfig.site.language,
title: source.sourceConfig.site.title,
description: source.sourceConfig.site.description,
baseUrl: source.sourceConfig.site.baseUrl,
language: source.sourceConfig.site.language,
lastBuildDate: rssDateFormatter.string(from: .init()),
publicationDate: publicationDate,
items: items,
userDefined: sourceConfig.site.userDefined
userDefined: source.sourceConfig.site.userDefined
)

try templateRenderer.render(
template: "rss",
with: rssCtx.context,
to:
destinationUrl
.appendingPathComponent(sourceConfig.config.contents.rss.output)
.appendingPathComponent(
source.sourceConfig.config.contents.rss.output
)
)
}
}
5 changes: 3 additions & 2 deletions Sources/ToucanSDK/Toucan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ public struct Toucan {
try sitemapRenderer.render()

let rssRenderer = RSSRenderer(
sourceConfig: source.sourceConfig,
source: source,
destinationUrl: workDirUrl,
fileManager: .default,
templateRenderer: templateRenderer,
pageBundles: source.rssPageBundles()
pageBundles: source.rssPageBundles(),
logger: logger
)
try rssRenderer.render()

Expand Down
Loading