Blob


1 (ns blog.gemini
2 (:require
3 [blog.time :as time]
4 [blog.gemtext :as gemtext]))
6 (defn with-page [_ & body]
7 (gemtext/unparse
8 (list
9 [:verbatim
10 " _
11 _ _ _ _ _ __ ___ | |__
12 | | | | | | | '_ ` _ \\| '_ \\ Writing about things,
13 | |_| | |_| | | | | | | | | | sometimes.
14 \\__, |\\__,_|_| |_| |_|_| |_|
15 |___/"]
16 [:paragraph ""]
17 [:link "/" "Home"]
18 [:link "/tags.gmi" "All Tags"]
19 [:link "/pages/projects.gmi" "Projects"]
20 [:paragraph ""]
21 body
22 [:paragraph ""]
23 [:paragraph ""]
24 [:paragraph ""]
25 [:paragraph "-- text: CC-BY-SA-4.0; code: ISC (unless specified otherwise)"]
26 [:paragraph "Blog proudly generated with Clojure"]
27 [:link "https://git.omarpolo.com/blog/" "sources"])))
29 (defn post-fragment
30 [{:keys [full? title-with-link?]}
31 {:keys [title date slug tags short body toot music xkcd] :as post}]
32 (list
33 (if title-with-link?
34 [:link (str "/post/" slug ".gmi") title]
35 [(if full? :h1 :h2) title])
36 (when full?
37 [:paragraph ""])
38 [:paragraph (str "Written by Omar Polo on " (time/fmt-loc date)
39 (when music
40 (str " while listening to " (:title music) (when-let [by (:by music)]
41 (str " by " by)) ))
42 ".")]
43 [:paragraph "Tagged with:"]
44 (map #(vector :link (str "/tag/" (name %) ".gmi") (str "#" (name %)))
45 tags)
46 (when xkcd
47 [:link (str "https://xkcd.com/" xkcd) (format "Relevant XKCD – #%d" xkcd)])
48 (if full?
49 (list [:paragraph ""]
50 (gemtext/parse body))
51 (when short [:blockquote short]))
52 [:paragraph ""]))
54 (defn home-page [{:keys [posts has-next has-prev nth]}]
55 (with-page {}
56 [:h2 "Recent posts"]
57 [:paragraph ""]
58 (map (partial post-fragment {:title-with-link? true})
59 posts)
60 (when has-prev
61 [:link (str "/"
62 (if (= (dec nth) 1)
63 "index"
64 (dec nth))
65 ".gmi")
66 "Newer Posts"])
67 (when has-next
68 [:link (str "/" (inc nth) ".gmi")
69 "Older Posts"])))
71 (defn custom-page [{:keys [body]}]
72 (with-page {}
73 (gemtext/parse body)))
75 (defn post-page [{:keys [title short] :as post}]
76 (with-page {}
77 (post-fragment {:full? true}
78 post)))
80 (defn tags-page [tags]
81 (with-page {}
82 [:h2 "All tags"]
83 [:paragraph ""]
84 (map #(vector :link (str "/tag/" (name %) ".gmi") (str "#" (name %)))
85 (sort (fn [a b]
86 (compare (.toLowerCase (name a))
87 (.toLowerCase (name b)))) tags))))
89 (defn tag-page [tag posts]
90 (with-page {}
91 [:h2 (format "Posts tagged with #%s" tag)]
92 [:paragraph ""]
93 (map (partial post-fragment {:title-with-link? true})
94 (->> posts
95 (sort-by :date)
96 (reverse)))))