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