summaryrefslogtreecommitdiff
path: root/src/core.clj
blob: b2b0d089d9adab1fea158c7c3edc7bd2645a47d8 (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
(ns core
  (:require [clojure.java.io :as io]
            [pages :refer [pages e-404]]))

(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 build []
  (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)))))
  (spit (io/file "target/html/404.html") (str (e-404))))

(defn -main []
  (clean)
  (build))