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]]))
6 ddc03123 2020-03-28 op (defn link-item [{:keys [url text]}]
7 ddc03123 2020-03-28 op [:li [:a {:href url} text]])
9 ddc03123 2020-03-28 op (defn header [{:keys [tags]}]
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"})]]
17 ddc03123 2020-03-28 op [:h1 [:a {:href "/"} "yumh"]]
18 ddc03123 2020-03-28 op [:p "writing about things, sometimes."]]]))
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"}
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 "")}
33 ddc03123 2020-03-28 op [:p "Blog powered by "
34 ddc03123 2020-03-28 op [:code "(clojure)"]]]]))
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}]
41 ddc03123 2020-03-28 op [:h1 (if title-with-link?
42 b5238953 2020-03-29 op [:a {:href (str "/post/" slug ".html")} 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 %))])
50 ddc03123 2020-03-28 op (markdown->hiccup default-config body)
51 ddc03123 2020-03-28 op [:p short])]])
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})
58 ddc03123 2020-03-28 op [:nav.post-navigation
60 ddc03123 2020-03-28 op [:a.prev {:href (str "/" (if (= (dec nth) 1)
62 ddc03123 2020-03-28 op (dec nth)) ".html")}
63 ddc03123 2020-03-28 op "« Newer Posts"])
65 ddc03123 2020-03-28 op [:a.next {:href (str "/" (inc nth) ".html")}
66 ddc03123 2020-03-28 op "Older Posts »"])]))
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}
75 ddc03123 2020-03-28 op (defn tags-page
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"]
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))]]))
87 ddc03123 2020-03-28 op (defn tag-page
89 ddc03123 2020-03-28 op (with-page {:title (str "Posts tagged with #" 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})
94 ddc03123 2020-03-28 op (sort-by :date)