Skip to content

Commit bc71c84

Browse files
committed
feat: Make it possible to supply a dateKeyPath for the Atom feed, which determines how the <updated> element gets its value
1 parent 319cb57 commit bc71c84

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/Saga/Atom.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import Foundation
1717
/// - author: The author of the articles.
1818
/// - baseURL: The base URL of your website, for example https://www.loopwerk.io.
1919
/// - summary: An optional function which takes an `Item` and returns its summary.
20+
/// - dateKeyPath: A keypath to the date property to use for the <updated> field. Defaults to `\.lastModified`.
2021
/// - Returns: A function which takes a rendering context, and returns a string.
21-
public func atomFeed<Context: AtomContext, M>(title: String, author: String? = nil, baseURL: URL, summary: ((Item<M>) -> String?)? = nil) -> (_ context: Context) -> String where Context.M == M {
22+
public func atomFeed<Context: AtomContext, M>(title: String, author: String? = nil, baseURL: URL, summary: ((Item<M>) -> String?)? = nil, dateKeyPath: KeyPath<Item<M>, Date> = \.lastModified) -> (_ context: Context) -> String where Context.M == M {
2223
let RFC3339_DF = ISO8601DateFormatter()
2324

2425
return { context in
@@ -60,7 +61,7 @@ public func atomFeed<Context: AtomContext, M>(title: String, author: String? = n
6061

6162
entryElement.addChild(idElement)
6263
entryElement.addChild(XMLElement(name: "title", stringValue: item.title))
63-
entryElement.addChild(XMLElement(name: "updated", stringValue: RFC3339_DF.string(from: item.lastModified)))
64+
entryElement.addChild(XMLElement(name: "updated", stringValue: RFC3339_DF.string(from: item[keyPath: dateKeyPath])))
6465

6566
if let summary, let summaryString = summary(item) {
6667
let summaryElement = XMLElement(name: "summary", stringValue: summaryString)

0 commit comments

Comments
 (0)