From cfde03889f6a17e12a2e5a47163e6f55fe657e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20B=C3=B6decs?= Date: Wed, 18 Dec 2024 15:42:24 +0100 Subject: [PATCH] Fix custom user defined keys for RSS' (#58) - add support for global user defined keys - add support for page bundle user defined keys --- Sources/ToucanSDK/Context/RSSContext.swift | 30 +++++++++++++++++++ Sources/ToucanSDK/Renderers/RSSRenderer.swift | 11 ++++--- 2 files changed, 37 insertions(+), 4 deletions(-) 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)