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 ddc03123 2020-03-28 op (link-item {:url "/tags.html", :text "All Tags"})]]
16 ddc03123 2020-03-28 op [:div
17 ddc03123 2020-03-28 op [:h1 [:a {:href "/"} "yumh"]]
18 ddc03123 2020-03-28 op [:p "writing about things, sometimes."]]]))
19 ddc03123 2020-03-28 op
20 ddc03123 2020-03-28 op (defn with-page
21 ddc03123 2020-03-28 op [{:keys [title class], :as d} & body]
22 ddc03123 2020-03-28 op (html5 {:lang "en"}
23 ddc03123 2020-03-28 op [:head
24 ddc03123 2020-03-28 op [:meta {:charset "utf8"}]
25 ddc03123 2020-03-28 op [:meta {:name "viewport", :content "width=device-width, initial-scale=1"}]
26 ddc03123 2020-03-28 op [:link {:rel "shortcut icon", :href "/favicon.ico"}]
27 ddc03123 2020-03-28 op [:title title]
28 ddc03123 2020-03-28 op (include-css "/css/style.css")]
29 ddc03123 2020-03-28 op [:body {:class (or class "")}
30 ddc03123 2020-03-28 op (header d)
31 ddc03123 2020-03-28 op [:main body]
32 ddc03123 2020-03-28 op [:footer
33 ddc03123 2020-03-28 op [:p "Blog powered by "
34 ddc03123 2020-03-28 op [:code "(clojure)"]]]]))
35 ddc03123 2020-03-28 op
36 ddc03123 2020-03-28 op (defn post-fragment
37 ddc03123 2020-03-28 op [{:keys [full? title-with-link?]}
38 ddc03123 2020-03-28 op {:keys [title date slug tags short body], :as post}]
39 ddc03123 2020-03-28 op [:article
40 ddc03123 2020-03-28 op [:header
41 ddc03123 2020-03-28 op [:h1 (if title-with-link?
42 b5238953 2020-03-29 op [:a {:href (str "/post/" slug ".html")} title]
43 ddc03123 2020-03-28 op title)]
44 ddc03123 2020-03-28 op [:p.author "Written by " [:em "Omar Polo"] " on " (time/fmt-loc date)]
45 ddc03123 2020-03-28 op [:ul.tags (map #(vector :li [:a {:href (str "/tag/" (name %) ".html")}
46 ddc03123 2020-03-28 op (str "#" (name %))])
47 ddc03123 2020-03-28 op tags)]]
48 ddc03123 2020-03-28 op [:section
49 ddc03123 2020-03-28 op (if full?
50 ddc03123 2020-03-28 op (markdown->hiccup default-config body)
51 ddc03123 2020-03-28 op [:p short])]])
52 ddc03123 2020-03-28 op
53 ddc03123 2020-03-28 op (defn home-page
54 ddc03123 2020-03-28 op [{:keys [posts has-next has-prev nth]}]
55 ddc03123 2020-03-28 op (with-page {:title "Home"}
56 ddc03123 2020-03-28 op (map (partial post-fragment {:title-with-link? true})
57 ddc03123 2020-03-28 op posts)
58 ddc03123 2020-03-28 op [:nav.post-navigation
59 ddc03123 2020-03-28 op (if has-prev
60 ddc03123 2020-03-28 op [:a.prev {:href (str "/" (if (= (dec nth) 1)
61 ddc03123 2020-03-28 op "index"
62 ddc03123 2020-03-28 op (dec nth)) ".html")}
63 ddc03123 2020-03-28 op "« Newer Posts"])
64 ddc03123 2020-03-28 op (if has-next
65 ddc03123 2020-03-28 op [:a.next {:href (str "/" (inc nth) ".html")}
66 ddc03123 2020-03-28 op "Older Posts »"])]))
67 ddc03123 2020-03-28 op
68 ddc03123 2020-03-28 op (defn post-page
69 ddc03123 2020-03-28 op [{:keys [title], :as post}]
70 ddc03123 2020-03-28 op (with-page {:title title
71 ddc03123 2020-03-28 op :class "article"}
72 ddc03123 2020-03-28 op (post-fragment {:full? true}
73 ddc03123 2020-03-28 op post)))
74 ddc03123 2020-03-28 op
75 ddc03123 2020-03-28 op (defn tags-page
76 ddc03123 2020-03-28 op [tags]
77 ddc03123 2020-03-28 op (with-page {:title "All tags"
78 ddc03123 2020-03-28 op :class "tags"}
79 ddc03123 2020-03-28 op [:h2 "All tags"]
80 ddc03123 2020-03-28 op [:nav
81 ddc03123 2020-03-28 op [:ul
82 ddc03123 2020-03-28 op (map #(vector :li [:a {:href (str "/tag/" (name %) ".html")} (str "#" (name %))])
83 ddc03123 2020-03-28 op (sort (fn [a b]
84 ddc03123 2020-03-28 op (compare (.toLowerCase (name a))
85 ddc03123 2020-03-28 op (.toLowerCase (name b)))) tags))]]))
86 ddc03123 2020-03-28 op
87 ddc03123 2020-03-28 op (defn tag-page
88 ddc03123 2020-03-28 op [tag posts]
89 ddc03123 2020-03-28 op (with-page {:title (str "Posts tagged with #" tag)
90 ddc03123 2020-03-28 op :class "tag"}
91 ddc03123 2020-03-28 op [:h2 "Post tagged with " [:code "#" tag]]
92 ddc03123 2020-03-28 op (map (partial post-fragment {:title-with-link? true})
93 ddc03123 2020-03-28 op (->> posts
94 ddc03123 2020-03-28 op (sort-by :date)
95 ddc03123 2020-03-28 op (reverse)))))