Blob


1 (ns blog.rss
2 (:require
3 [blog.gemtext :as gemtext]
4 [blog.time :as time]
5 [clojure.data.xml :refer :all]
6 [commonmark-hiccup.core :refer [markdown->hiccup default-config]]
7 [hiccup.core :as hiccup]))
9 (defn item [linkfn {:keys [title date slug tags short body gemtext?]}]
10 (let [link (linkfn slug)]
11 [:item
12 [:title title]
13 (when body
14 [:description
15 [:-cdata
16 (hiccup/html
17 (if gemtext?
18 (-> body gemtext/parse gemtext/to-hiccup)
19 (markdown->hiccup default-config body)))]])
20 [:guid link]
21 [:link link]
22 [:pubDate (time/fmt-rfc-2822 date)]]))
24 (defn feed [linkfn posts]
25 (indent-str
26 (sexp-as-element
27 [:rss {:version "2.0" :xmlns:atom "http://www.w3.org/2005/Atom"}
28 [:channel
29 [:title "yumh"]
30 [:description "Writing about things, sometimes"]
31 [:link "https://www.omarpolo.com"]
32 ;; fails to validate?
33 ;; [:atom:link {:href "https://www.omarpolo.com/rss.xml" :ref "self" :type "application/rss+xml"} nil]
34 (map (partial item linkfn)
35 posts)]])))