Blame


1 4ce98dba 2020-10-03 op (ns blog.gemini
2 4ce98dba 2020-10-03 op (:require
3 4ce98dba 2020-10-03 op [blog.time :as time]
4 4ce98dba 2020-10-03 op [blog.gemtext :as gemtext]))
5 4ce98dba 2020-10-03 op
6 4ce98dba 2020-10-03 op (defn with-page [_ & body]
7 4ce98dba 2020-10-03 op (gemtext/unparse
8 4ce98dba 2020-10-03 op (list
9 4ce98dba 2020-10-03 op [:verbatim
10 4ce98dba 2020-10-03 op " _
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 \\__, |\\__,_|_| |_| |_|_| |_|
15 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 ""]
21 4ce98dba 2020-10-03 op body
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"])))
28 4ce98dba 2020-10-03 op
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}]
32 4ce98dba 2020-10-03 op (list
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])
36 4ce98dba 2020-10-03 op (when full?
37 4ce98dba 2020-10-03 op [:paragraph ""])
38 4ce98dba 2020-10-03 op [:paragraph (str "Written by Omar Polo on " (time/fmt-loc date)
39 4ce98dba 2020-10-03 op (when music
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)) ))
42 4ce98dba 2020-10-03 op ".")]
43 4ce98dba 2020-10-03 op [:paragraph "Tagged with:"]
44 4ce98dba 2020-10-03 op (map #(vector :link (str "/tag/" (name %) ".gmi") (str "#" (name %)))
45 4ce98dba 2020-10-03 op tags)
46 4ce98dba 2020-10-03 op (when xkcd
47 4ce98dba 2020-10-03 op [:link (str "https://xkcd.com/" xkcd) (format "Relevant XKCD – #%d" xkcd)])
48 4ce98dba 2020-10-03 op (if full?
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 ""]))
53 4ce98dba 2020-10-03 op
54 4ce98dba 2020-10-03 op (defn home-page [{:keys [posts has-next has-prev nth]}]
55 4ce98dba 2020-10-03 op (with-page {}
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})
59 4ce98dba 2020-10-03 op posts)
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)
63 4ce98dba 2020-10-03 op "index"
64 4ce98dba 2020-10-03 op (dec nth))
65 4ce98dba 2020-10-03 op ".gmi")
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"])))
70 4ce98dba 2020-10-03 op
71 d72c4e8f 2020-10-05 op (defn custom-page [{:keys [body]}]
72 d72c4e8f 2020-10-05 op (with-page {}
73 d72c4e8f 2020-10-05 op (gemtext/parse body)))
74 d72c4e8f 2020-10-05 op
75 4ce98dba 2020-10-03 op (defn post-page [{:keys [title short] :as post}]
76 4ce98dba 2020-10-03 op (with-page {}
77 4ce98dba 2020-10-03 op (post-fragment {:full? true}
78 4ce98dba 2020-10-03 op post)))
79 4ce98dba 2020-10-03 op
80 4ce98dba 2020-10-03 op (defn tags-page [tags]
81 4ce98dba 2020-10-03 op (with-page {}
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))))
88 4ce98dba 2020-10-03 op
89 4ce98dba 2020-10-03 op (defn tag-page [tag posts]
90 4ce98dba 2020-10-03 op (with-page {}
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})
94 4ce98dba 2020-10-03 op (->> posts
95 4ce98dba 2020-10-03 op (sort-by :date)
96 4ce98dba 2020-10-03 op (reverse)))))