4 [blog.gemtext :as gemtext]
5 [clojure.string :as str]
6 [clojure.walk :as walk]
7 [hiccup.page :refer [html5 include-css]]
8 [commonmark-hiccup.core :refer [markdown->hiccup default-config]]))
10 (defn link-item [{:keys [url text title]}]
11 [:li [:a (cond-> {:href url}
12 title (assoc :title title))
15 (defn header [{:keys [skip-banner?]}]
20 (link-item {:url "/", :text "Home"})
21 (link-item {:url "/tags.html", :text "All Tags"})
22 (link-item {:url "/pages/projects.html", :text "Projects"})
23 (link-item {:url "gemini://gemini.omarpolo.com" :text "gemini://"
24 :title "This website in the gemini space."})]]
25 (when-not skip-banner?
27 [:h1 [:a {:href "/"} "yumh"]]
28 [:p "writing about things, sometimes."]])]))
31 [{:keys [title class description skip-banner?], :as d} & body]
34 [:meta {:charset "utf8"}]
35 [:meta {:name "viewport", :content "width=device-width, initial-scale=1"}]
36 [:link {:rel "shortcut icon", :href "/favicon.ico"}]
37 [:link {:rel "alternative" :type "application/rss+xml" :href "https://www.omarpolo.com/rss.xml"}]
39 [:meta {:name "description" :content description}])
41 (include-css "/css/style.css")]
42 [:body {:class (or class "")}
46 [:p "text: CC-BY-SA-4.0; code: ISC (unless specified otherwise)"]
47 [:p "Blog proudly generated with "
48 [:a {:href "https://git.omarpolo.com/blog/"}
49 [:code "(clojure)"]]]]
51 [:img {:src "https://goatcounter.omarpolo.com/count?p=/test-img"}]]
54 if (window.location.host !== 'omarpolo.com')
55 window.goatcounter = {no_onload: true}
57 [:script {:data-goatcounter "https://goatcounter.omarpolo.com/count"
59 :src "//goatcounter.omarpolo.com/count.js"}]]))
62 "traverse `doc` and replace every link to an image to an `img` tag."
66 (if-not (and (vector? item) (= (first item) :a))
68 (let [[_ {:keys [href] :as attrs} text] item]
75 [{:keys [full? title-with-link?]}
76 {:keys [title date slug tags short body toot music xkcd gemtext?], :as post}]
83 [:a {:href (str "/post/" slug ".html")} title]
85 [:p.author "Written by " [:em "Omar Polo"] " on " (time/fmt-loc date)
88 (list " while listening to " [:a {:href (:url music)
91 "“" [:em (:title music)] "”"
92 (when-let [by (:by music)]
93 (list " by " [:em by]))]))
95 [:ul.tags (map #(vector :li [:a {:href (str "/tag/" (name %) ".html")}
99 [:p [:a {:href (str "https://xkcd.com/" xkcd)
106 :rel "noopener"} "Comments over ActivityPub"]])]
110 (-> body gemtext/parse gemtext/to-hiccup)
111 (markdown->hiccup default-config body))
115 [{:keys [posts has-next has-prev nth]}]
116 (with-page {:title "Home"}
117 (map (partial post-fragment {:title-with-link? true})
119 [:nav.post-navigation
121 [:a.prev {:href (str "/" (if (= (dec nth) 1)
126 [:a.next {:href (str "/" (inc nth) ".html")}
129 (defn custom-page [{:keys [title body]}]
130 (with-page {:title title
132 ;; warning: hack ahead
135 (if-not (and (vector? item) (= (first item) :a))
137 (let [[_ attrs & body] item]
138 [:a (update attrs :href str/replace #"\.gmi$" ".html")
140 (-> body gemtext/parse gemtext/to-hiccup))))
143 [{:keys [title short], :as post}]
144 (with-page {:title title
147 (post-fragment {:full? true}
152 (with-page {:title "All tags"
157 (map #(vector :li [:a {:href (str "/tag/" (name %) ".html")} (str "#" (name %))])
159 (compare (.toLowerCase (name a))
160 (.toLowerCase (name b)))) tags))]]))
164 (with-page {:title (str "Posts tagged with #" tag)
166 [:h2 "Posts tagged with " [:code "#" tag]]
167 (map (partial post-fragment {:title-with-link? true})