diff --git a/Sources/ToucanSDK/Context/RSSContext.swift b/Sources/ToucanSDK/Context/RSSContext.swift index 2283b155..01e1fb52 100644 --- a/Sources/ToucanSDK/Context/RSSContext.swift +++ b/Sources/ToucanSDK/Context/RSSContext.swift @@ -12,6 +12,20 @@ struct RSSContext { let title: String let description: String let publicationDate: String + + let userDefined: [String: Any] + + var context: [String: Any] { + userDefined.recursivelyMerged( + with: [ + "permalink": permalink, + "title": title, + "description": description, + "publicationDate": publicationDate, + ] + ) + .sanitized() + } } let title: String @@ -21,4 +35,20 @@ struct RSSContext { let lastBuildDate: String let publicationDate: String let items: [Item] + let userDefined: [String: Any] + + var context: [String: Any] { + userDefined.recursivelyMerged( + with: [ + "title": title, + "description": description, + "baseUrl": baseUrl, + "language": language as Any, + "lastBuildDate": lastBuildDate, + "publicationDate": publicationDate, + "items": items.map(\.context), + ] + ) + .sanitized() + } } diff --git a/Sources/ToucanSDK/Renderers/RSSRenderer.swift b/Sources/ToucanSDK/Renderers/RSSRenderer.swift index 9d722779..845fa4c9 100644 --- a/Sources/ToucanSDK/Renderers/RSSRenderer.swift +++ b/Sources/ToucanSDK/Renderers/RSSRenderer.swift @@ -27,7 +27,8 @@ struct RSSRenderer { permalink: item.permalink, title: item.title, description: item.description, - publicationDate: item.date.rss + publicationDate: item.date.rss, + userDefined: item.baseContext ) } @@ -37,18 +38,20 @@ struct RSSRenderer { items.first?.publicationDate ?? rssDateFormatter.string(from: .init()) - let context = RSSContext( + let rssCtx = RSSContext( title: sourceConfig.site.title, description: sourceConfig.site.description, baseUrl: sourceConfig.site.baseUrl, language: sourceConfig.site.language, lastBuildDate: rssDateFormatter.string(from: .init()), publicationDate: publicationDate, - items: items + items: items, + userDefined: sourceConfig.site.userDefined ) + try templateRenderer.render( template: "rss", - with: context, + with: rssCtx.context, to: destinationUrl .appendingPathComponent(sourceConfig.config.contents.rss.output)