From ba451a6b9ba283b4c519283a45aa523662854677 Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Mon, 3 Aug 2026 12:55:54 -0400 Subject: added rss2 feed --- feed.typ | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 feed.typ (limited to 'feed.typ') diff --git a/feed.typ b/feed.typ new file mode 100644 index 0000000..75639e0 --- /dev/null +++ b/feed.typ @@ -0,0 +1,54 @@ +// 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). + +#import "/global/common.typ": baseurl + +#let xml-escape(s) = s.replace("&", "&").replace("<", "<").replace(">", ">") + +// ISO date ("2026-07-28") to RFC 822 ("Tue, 28 Jul 2026 00:00:00 GMT"). +#let rfc822(iso) = { + let (y, m, d) = iso.split("-").map(int) + datetime(year: y, month: m, day: d).display( + "[weekday repr:short], [day] [month repr:short] [year] 00:00:00 GMT" + ) +} + +#let feed-xml(site-info) = { + let pages = site-info.pages + let ids = pages.keys().filter(k => k.starts-with("post/")) + + let items = () + 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" + + let lines = ( + " ", + " " + xml-escape(title) + "", + " " + url + "", + " " + url + "", + ) + if "date" in p { + lines.push(" " + rfc822(p.date) + "") + } + if "description" in p { + lines.push(" " + xml-escape(p.description) + "") + } + lines.push(" ") + items.push(lines.join("\n")) + } + + ( + "", + "", + "", + " " + xml-escape(site-info.title) + "", + " " + baseurl + "/", + " Posts from " + xml-escape(site-info.title) + " (" + baseurl + ")", + items.join("\n"), + "", + "", + "", + ).join("\n") +} -- cgit v1.2.3