Skip to content

Commit

Permalink
Fix custom user defined keys for RSS' (#58)
Browse files Browse the repository at this point in the history
- add support for global user defined keys 
- add support for page bundle user defined keys
  • Loading branch information
tib authored Dec 18, 2024
1 parent 5510985 commit cfde038
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
30 changes: 30 additions & 0 deletions Sources/ToucanSDK/Context/RSSContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
11 changes: 7 additions & 4 deletions Sources/ToucanSDK/Renderers/RSSRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand All @@ -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)
Expand Down

0 comments on commit cfde038

Please sign in to comment.