Blame


1 ddc03123 2020-03-28 op (ns blog.templates
2 ddc03123 2020-03-28 op (:require [blog.time :as time]
3 ddc03123 2020-03-28 op [hiccup.page :refer [html5 include-css]]
4 ddc03123 2020-03-28 op [commonmark-hiccup.core :refer [markdown->hiccup default-config]]))
5 ddc03123 2020-03-28 op
6 ddc03123 2020-03-28 op (defn link-item [{:keys [url text]}]
7 ddc03123 2020-03-28 op [:li [:a {:href url} text]])
8 ddc03123 2020-03-28 op
9 ddc03123 2020-03-28 op (defn header [{:keys [tags]}]
10 ddc03123 2020-03-28 op (list
11 ddc03123 2020-03-28 op [:header
12 ddc03123 2020-03-28 op [:nav
13 ddc03123 2020-03-28 op [:ul
14 ddc03123 2020-03-28 op (link-item {:url "/", :text "Home"})
15 dcb77f40 2020-06-03 op (link-item {:url "/tags.html", :text "All Tags"})
16 dcb77f40 2020-06-03 op (link-item {:url "https://git.omarpolo.com", :text "Git repos"})]]
17 ddc03123 2020-03-28 op [:div
18 ddc03123 2020-03-28 op [:h1 [:a {:href "/"} "yumh"]]
19 ddc03123 2020-03-28 op [:p "writing about things, sometimes."]]]))
20 ddc03123 2020-03-28 op
21 ddc03123 2020-03-28 op (defn with-page
22 4e33b4c7 2020-06-27 op [{:keys [title class description], :as d} & body]
23 ddc03123 2020-03-28 op (html5 {:lang "en"}
24 ddc03123 2020-03-28 op [:head
25 ddc03123 2020-03-28 op [:meta {:charset "utf8"}]
26 ddc03123 2020-03-28 op [:meta {:name "viewport", :content "width=device-width, initial-scale=1"}]
27 ddc03123 2020-03-28 op [:link {:rel "shortcut icon", :href "/favicon.ico"}]
28 4f9bd2e2 2020-03-30 op [:link {:rel "alternative" :type "application/rss+xml" :href "https://www.omarpolo.com/rss.xml"}]
29 4e33b4c7 2020-06-27 op (when description
30 4e33b4c7 2020-06-27 op [:meta {:name "description" :content description}])
31 ddc03123 2020-03-28 op [:title title]
32 ddc03123 2020-03-28 op (include-css "/css/style.css")]
33 ddc03123 2020-03-28 op [:body {:class (or class "")}
34 ddc03123 2020-03-28 op (header d)
35 ddc03123 2020-03-28 op [:main body]
36 ddc03123 2020-03-28 op [:footer
37 7dd59802 2020-04-03 op [:p "Blog proudly generated with "
38 be1f9258 2020-06-05 op [:code "(clojure)"]]]
39 be1f9258 2020-06-05 op [:noscript
40 be1f9258 2020-06-05 op [:img {:src "https://goatcounter.omarpolo.com/count?p=/test-img"}]]
41 be1f9258 2020-06-05 op [:script {:data-goatcounter "https://goatcounter.omarpolo.com/count"
42 be1f9258 2020-06-05 op :async true
43 be1f9258 2020-06-05 op :src "//goatcounter.omarpolo.com/count.js"}]]))
44 ddc03123 2020-03-28 op
45 ddc03123 2020-03-28 op (defn post-fragment
46 ddc03123 2020-03-28 op [{:keys [full? title-with-link?]}
47 37740488 2020-06-05 op {:keys [title date slug tags short body toot], :as post}]
48 ddc03123 2020-03-28 op [:article
49 ddc03123 2020-03-28 op [:header
50 37740488 2020-06-05 op [(if full?
51 37740488 2020-06-05 op :h1
52 37740488 2020-06-05 op :h2.fragment)
53 37740488 2020-06-05 op (if title-with-link?
54 37740488 2020-06-05 op [:a {:href (str "/post/" slug ".html")} title]
55 37740488 2020-06-05 op title)]
56 ddc03123 2020-03-28 op [:p.author "Written by " [:em "Omar Polo"] " on " (time/fmt-loc date)]
57 ddc03123 2020-03-28 op [:ul.tags (map #(vector :li [:a {:href (str "/tag/" (name %) ".html")}
58 ddc03123 2020-03-28 op (str "#" (name %))])
59 37740488 2020-06-05 op tags)]
60 37740488 2020-06-05 op (when toot
61 37740488 2020-06-05 op [:p [:a {:href toot,
62 37740488 2020-06-05 op :target "_blank"
63 37740488 2020-06-05 op :rel "noopener"} "Comments over ActivityPub"]])]
64 ddc03123 2020-03-28 op [:section
65 ddc03123 2020-03-28 op (if full?
66 ddc03123 2020-03-28 op (markdown->hiccup default-config body)
67 ddc03123 2020-03-28 op [:p short])]])
68 ddc03123 2020-03-28 op
69 ddc03123 2020-03-28 op (defn home-page
70 ddc03123 2020-03-28 op [{:keys [posts has-next has-prev nth]}]
71 ddc03123 2020-03-28 op (with-page {:title "Home"}
72 ddc03123 2020-03-28 op (map (partial post-fragment {:title-with-link? true})
73 ddc03123 2020-03-28 op posts)
74 ddc03123 2020-03-28 op [:nav.post-navigation
75 ddc03123 2020-03-28 op (if has-prev
76 ddc03123 2020-03-28 op [:a.prev {:href (str "/" (if (= (dec nth) 1)
77 ddc03123 2020-03-28 op "index"
78 ddc03123 2020-03-28 op (dec nth)) ".html")}
79 ddc03123 2020-03-28 op "« Newer Posts"])
80 ddc03123 2020-03-28 op (if has-next
81 ddc03123 2020-03-28 op [:a.next {:href (str "/" (inc nth) ".html")}
82 ddc03123 2020-03-28 op "Older Posts »"])]))
83 ddc03123 2020-03-28 op
84 ddc03123 2020-03-28 op (defn post-page
85 4e33b4c7 2020-06-27 op [{:keys [title short], :as post}]
86 ddc03123 2020-03-28 op (with-page {:title title
87 4e33b4c7 2020-06-27 op :class "article"
88 4e33b4c7 2020-06-27 op :description short}
89 ddc03123 2020-03-28 op (post-fragment {:full? true}
90 ddc03123 2020-03-28 op post)))
91 ddc03123 2020-03-28 op
92 ddc03123 2020-03-28 op (defn tags-page
93 ddc03123 2020-03-28 op [tags]
94 ddc03123 2020-03-28 op (with-page {:title "All tags"
95 ddc03123 2020-03-28 op :class "tags"}
96 ddc03123 2020-03-28 op [:h2 "All tags"]
97 ddc03123 2020-03-28 op [:nav
98 ddc03123 2020-03-28 op [:ul
99 ddc03123 2020-03-28 op (map #(vector :li [:a {:href (str "/tag/" (name %) ".html")} (str "#" (name %))])
100 ddc03123 2020-03-28 op (sort (fn [a b]
101 ddc03123 2020-03-28 op (compare (.toLowerCase (name a))
102 ddc03123 2020-03-28 op (.toLowerCase (name b)))) tags))]]))
103 ddc03123 2020-03-28 op
104 ddc03123 2020-03-28 op (defn tag-page
105 ddc03123 2020-03-28 op [tag posts]
106 ddc03123 2020-03-28 op (with-page {:title (str "Posts tagged with #" tag)
107 ddc03123 2020-03-28 op :class "tag"}
108 0ff91bf2 2020-06-04 op [:h2 "Posts tagged with " [:code "#" tag]]
109 ddc03123 2020-03-28 op (map (partial post-fragment {:title-with-link? true})
110 ddc03123 2020-03-28 op (->> posts
111 ddc03123 2020-03-28 op (sort-by :date)
112 ddc03123 2020-03-28 op (reverse)))))