From 84aff405b134337ad335453f339f46bd86e7bf27 Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Mon, 3 Aug 2026 13:23:49 -0400 Subject: added atom feed --- feed.typ | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'feed.typ') diff --git a/feed.typ b/feed.typ index 75639e0..3a5fd21 100644 --- a/feed.typ +++ b/feed.typ @@ -1,5 +1,6 @@ -// RSS 2.0 feed for the blog posts, emitted as feed.xml by main.typ. -// Items are built from the metadata in site-info.pages (newest first). +// RSS 2.0 and Atom feeds for the blog posts, emitted as feed.xml and +// atom.xml by main.typ. Entries are built from the metadata in +// site-info.pages (newest first). #import "/global/common.typ": baseurl @@ -13,16 +14,25 @@ ) } -#let feed-xml(site-info) = { +// ISO date ("2026-07-28") to RFC 3339 ("2026-07-28T00:00:00Z"). +#let rfc3339(iso) = iso + "T00:00:00Z" + +#let _entries(site-info, item-fn) = { let pages = site-info.pages let ids = pages.keys().filter(k => k.starts-with("post/")) - let items = () + let entries = () for id in ids { let p = pages.at(id) let title = if "long-title" in p { p.long-title } else { p.title } let url = baseurl + "/" + id + ".html" + entries.push(item-fn(title, url, p)) + } + entries +} +#let feed-xml(site-info) = { + let items = _entries(site-info, (title, url, p) => { let lines = ( " ", " " + xml-escape(title) + "", @@ -36,8 +46,8 @@ lines.push(" " + xml-escape(p.description) + "") } lines.push(" ") - items.push(lines.join("\n")) - } + lines.join("\n") + }) ( "", @@ -52,3 +62,44 @@ "", ).join("\n") } + +// Atom (RFC 4287) feed, emitted as atom.xml by main.typ. +#let atom-xml(site-info) = { + let entries = _entries(site-info, (title, url, p) => { + let lines = ( + " ", + " " + xml-escape(title) + "", + " ", + " " + url + "", + ) + if "date" in p { + lines.push(" " + rfc3339(p.date) + "") + } + if "description" in p { + lines.push(" " + xml-escape(p.description) + "") + } + lines.push(" ") + lines.join("\n") + }) + + // newest post first, so its date is the feed's last-update time + let updated = rfc3339(site-info.pages.at( + site-info.pages.keys().filter(k => k.starts-with("post/")).first() + ).date) + + ( + "", + "", + " " + xml-escape(site-info.title) + "", + " ", + " ", + " " + baseurl + "/", + " " + updated + "", + " ", + " Kumar", + " ", + entries.join("\n"), + "", + "", + ).join("\n") +} -- cgit v1.2.3