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 441c3bcd 2020-11-19 op (defn feed-page [posts]
7 441c3bcd 2020-11-19 op (gemtext/unparse
8 441c3bcd 2020-11-19 op (list
9 7578b20e 2021-05-31 op [:header-1 "yumh"]
10 7578b20e 2021-05-31 op [:quote "Writing about things, sometimes"]
11 7578b20e 2021-05-31 op [:text ""]
12 441c3bcd 2020-11-19 op (for [post posts]
13 441c3bcd 2020-11-19 op (let [{:keys [title date slug]} post
14 441c3bcd 2020-11-19 op url (str "gemini://gemini.omarpolo.com/post/" slug ".gmi")]
15 ce07a90d 2020-12-01 op [:link url (str (time/fmt-iso8601 date) " - " title)])))))
16 441c3bcd 2020-11-19 op
17 4ce98dba 2020-10-03 op (defn with-page [_ & body]
18 4ce98dba 2020-10-03 op (gemtext/unparse
19 4ce98dba 2020-10-03 op (list
20 7578b20e 2021-05-31 op body
21 7578b20e 2021-05-31 op [:text ""]
22 7578b20e 2021-05-31 op [:text ""]
23 7578b20e 2021-05-31 op [:text ""]
24 4cb58f8e 2021-08-03 op [:text "-- text: CC-BY-SA-4.0; code: public domain unless specified otherwise"]
25 38b6ce11 2021-12-23 op [:text "For comments, write at < blog at omarpolo dot com > or @op@bsd.network in the fediverse."]
26 4cb58f8e 2021-08-03 op [:link "//git.omarpolo.com/blog/" "Capsule proudly assembled with Clojure"])))
27 7578b20e 2021-05-31 op
28 7578b20e 2021-05-31 op (defn with-default-template [_ & body]
29 7578b20e 2021-05-31 op (with-page {}
30 7578b20e 2021-05-31 op [:header-1 "yumh"]
31 7578b20e 2021-05-31 op [:quote "Writing about things, sometimes"]
32 7578b20e 2021-05-31 op [:text ""]
33 4ce98dba 2020-10-03 op [:link "/" "Home"]
34 4ce98dba 2020-10-03 op [:link "/tags.gmi" "All Tags"]
35 d72c4e8f 2020-10-05 op [:link "/pages/projects.gmi" "Projects"]
36 7578b20e 2021-05-31 op [:text ""]
37 7578b20e 2021-05-31 op body))
38 4ce98dba 2020-10-03 op
39 4ce98dba 2020-10-03 op (defn post-fragment
40 4ce98dba 2020-10-03 op [{:keys [full? title-with-link?]}
41 4ce98dba 2020-10-03 op {:keys [title date slug tags short body toot music xkcd] :as post}]
42 4ce98dba 2020-10-03 op (list
43 4ce98dba 2020-10-03 op (if title-with-link?
44 7578b20e 2021-05-31 op [:link (str "/post/" slug ".gmi") (str (time/fmt-iso8601 date) " - " title)]
45 7578b20e 2021-05-31 op [(if full? :header-1 :header-2) title])
46 7578b20e 2021-05-31 op (if full?
47 7578b20e 2021-05-31 op [:text ""]
48 7578b20e 2021-05-31 op [:quote short])
49 7578b20e 2021-05-31 op (when music
50 7578b20e 2021-05-31 op [:text (str "Written while listening to “" (:title music) "”"
51 7578b20e 2021-05-31 op (when-let [by (:by music)]
52 7578b20e 2021-05-31 op (str " by " by))
53 7578b20e 2021-05-31 op ".")])
54 4cb58f8e 2021-08-03 op (when full?
55 4cb58f8e 2021-08-03 op [:text (str "Published: " (time/fmt-iso8601 date))])
56 7578b20e 2021-05-31 op [:text "Tagged with:"]
57 4ce98dba 2020-10-03 op (map #(vector :link (str "/tag/" (name %) ".gmi") (str "#" (name %)))
58 40ca3ee3 2020-12-28 op (sort tags))
59 4ce98dba 2020-10-03 op (when xkcd
60 4ce98dba 2020-10-03 op [:link (str "https://xkcd.com/" xkcd) (format "Relevant XKCD – #%d" xkcd)])
61 7578b20e 2021-05-31 op (when full?
62 7578b20e 2021-05-31 op (list [:text ""]
63 7578b20e 2021-05-31 op (gemtext/parse body)))
64 7578b20e 2021-05-31 op [:text ""]))
65 4ce98dba 2020-10-03 op
66 4ce98dba 2020-10-03 op (defn home-page [{:keys [posts has-next has-prev nth]}]
67 7578b20e 2021-05-31 op (with-default-template
68 7578b20e 2021-05-31 op [:text ""]
69 4cb58f8e 2021-08-03 op [:text "Welcome to my gemlog! Sometimes I remember that I have a blog and post something here. My main interests are computer science, operating systems (BSDs in particular), programming languages (especially C, Go, LISP in its various incarnations). I also have an Italian capsule where I write about more casual stuff:"]
70 7578b20e 2021-05-31 op [:link "gemini://it.omarpolo.com" "l'angolo di yumh"]
71 7578b20e 2021-05-31 op [:text ""]
72 7578b20e 2021-05-31 op [:text "Some Gemini services on this capsule:"]
73 7578b20e 2021-05-31 op [:link "/cgi/man" "Look up a manpage"]
74 7578b20e 2021-05-31 op [:link "/cgi/gempkg" "Browse the OpenBSD ports tree"]
75 7578b20e 2021-05-31 op [:text ""]
76 7578b20e 2021-05-31 op [:header-2 "Recent posts"]
77 7578b20e 2021-05-31 op [:text ""]
78 4ce98dba 2020-10-03 op (map (partial post-fragment {:title-with-link? true})
79 4ce98dba 2020-10-03 op posts)
80 4ce98dba 2020-10-03 op (when has-prev
81 4ce98dba 2020-10-03 op [:link (str "/"
82 4ce98dba 2020-10-03 op (if (= (dec nth) 1)
83 4ce98dba 2020-10-03 op "index"
84 4ce98dba 2020-10-03 op (dec nth))
85 4ce98dba 2020-10-03 op ".gmi")
86 4ce98dba 2020-10-03 op "Newer Posts"])
87 4ce98dba 2020-10-03 op (when has-next
88 4ce98dba 2020-10-03 op [:link (str "/" (inc nth) ".gmi")
89 4ce98dba 2020-10-03 op "Older Posts"])))
90 4ce98dba 2020-10-03 op
91 d72c4e8f 2020-10-05 op (defn custom-page [{:keys [body]}]
92 7578b20e 2021-05-31 op (apply with-default-template (gemtext/parse body)))
93 d72c4e8f 2020-10-05 op
94 4ce98dba 2020-10-03 op (defn post-page [{:keys [title short] :as post}]
95 4ce98dba 2020-10-03 op (with-page {}
96 7578b20e 2021-05-31 op [:link ".." "↩ back to the index"]
97 7578b20e 2021-05-31 op [:text ""]
98 4ce98dba 2020-10-03 op (post-fragment {:full? true}
99 4ce98dba 2020-10-03 op post)))
100 4ce98dba 2020-10-03 op
101 4ce98dba 2020-10-03 op (defn tags-page [tags]
102 7578b20e 2021-05-31 op (with-default-template
103 7578b20e 2021-05-31 op [:header-2 "All tags"]
104 7578b20e 2021-05-31 op [:text ""]
105 4ce98dba 2020-10-03 op (map #(vector :link (str "/tag/" (name %) ".gmi") (str "#" (name %)))
106 4ce98dba 2020-10-03 op (sort (fn [a b]
107 4ce98dba 2020-10-03 op (compare (.toLowerCase (name a))
108 4ce98dba 2020-10-03 op (.toLowerCase (name b)))) tags))))
109 4ce98dba 2020-10-03 op
110 4ce98dba 2020-10-03 op (defn tag-page [tag posts]
111 7578b20e 2021-05-31 op (with-default-template
112 7578b20e 2021-05-31 op [:header-2 (format "Posts tagged with #%s" tag)]
113 7578b20e 2021-05-31 op [:text ""]
114 7578b20e 2021-05-31 op [:text "Note: not every post is currently available over Gemini."]
115 7578b20e 2021-05-31 op [:text ""]
116 4ce98dba 2020-10-03 op (map (partial post-fragment {:title-with-link? true})
117 4ce98dba 2020-10-03 op (->> posts
118 4ce98dba 2020-10-03 op (sort-by :date)
119 4ce98dba 2020-10-03 op (reverse)))))