(set-env!
 :source-paths #{"src"}
 :resource-paths #{"content"}
 :dependencies '[[perun "0.5.0-SNAPSHOT" :scope "test"]
                 [org.clojure/clojurescript "1.11.4"]
                 [adzerk/boot-cljs "2.1.5" :scope "test"]
                 [hiccup "2.0.0-alpha2" :exclusions [org.clojure/clojure]]
                 [garden "1.3.10"]
                 [org.martinklepsch/boot-garden "1.3.2-0"]
                 [pandeiro/boot-http "0.8.3" :exclusions [org.clojure/clojure]]])

(require '[io.perun :as perun]
         '[adzerk.boot-cljs :refer [cljs]]
         '[pandeiro.boot-http :refer [serve]]
         '[org.martinklepsch.boot-garden :refer [garden]]
         '[site.core])

(deftask build [o optimize? bool "Optimize css & js output"]
  (comp (perun/draft)
        (perun/pandoc :cmd-opts ["-f" "markdown" "-t" "html5"])
        (sift :to-resource #{#"^img/(.*)"})
        (sift :to-resource #{#"^extra/(.*)"})
        (sift :to-resource #{#"^CNAME"})
        (garden :styles-var 'site.styles/base :output-to "main.css" :pretty-print (if optimize? false true))
        ;(cljs :optimizations (if optimize? :advanced :none) :source-map (if optimize? false true))
        (perun/ttr)  ;; Time to read
        (perun/word-count)
        (perun/render :renderer 'site.core/page)
        (perun/permalink :filterer (fn [p] (not= (:slug p) "index")))
        (perun/collection :renderer 'site.core/page-blog
                          :filterer (fn [p] (:title p)) ; don't list anything without a title
                          :sortby :date
                          :page "blog/index.html" :out-dir "")
        (perun/sitemap :filename "sitemap.xml")
        (sift :move {#"^public/(.*)" "$1"}))) ; perun/render ignores out-dir for some reason



(deftask dev []
  (comp (watch)
        (build :optimize? false)
        (serve :port 8000 :resource-root "")))

(deftask publish []
  (comp (build :optimize? true)
        (target :dir #{"docs"})))
