blob: f13531e5051617c417470b1f89eca2855ddea0de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
(ns core
(:require [borkdude.html :refer [html]]
[clojure.java.io :as io]
[clojure.string :as str]))
(defn template [body]
(html [:html [:head] [:body [:<> body]]]))
(defn home []
(template
(html
[:h1 "home"])))
(defn about []
(template
(html
[:h1 "about"])))
(defn this-life
"blog post about this life"
[]
(template
(html
[:h1 "This life"])))
(defn something-else
"blog post about something else"
[]
(template
(html
[:h1 "Something else"])))
(something-else)
(def pages
{"/" home
"/about2" about
"/blog/this-life" this-life
"/blog/something-else" something-else})
(defn clean []
(let [target-dir (io/file "target")]
(when (.exists target-dir)
(doseq [file (file-seq target-dir)
:when (.isFile file)]
(io/delete-file file))
(doseq [dir (reverse (filter #(.isDirectory %) (file-seq target-dir)))
:when (not= dir target-dir)]
(.delete dir)))))
(defn compile []
(doseq [[path page-fn] pages]
(let [target-path (if (= path "/")
"target/html/index.html"
(str "target/html" path "/index.html"))
target-file (io/file target-path)]
(io/make-parents target-file)
(spit target-file (str (page-fn))))))
(defn -main []
(clean)
(compile))
|