diff --git a/src/buchdesmonats/core.clj b/src/buchdesmonats/core.clj index 59847e4..3e7aeac 100644 --- a/src/buchdesmonats/core.clj +++ b/src/buchdesmonats/core.clj @@ -6,7 +6,7 @@ [clojure.java.io :as io] [me.raynes.fs :as fs])) -(def config {:books-url "https://raw.github.com/CTHN/wiki-data/master/pages/projects/buch_des_monats.mkd" +(def *config* {:books-url "https://raw.github.com/CTHN/wiki-data/master/pages/projects/buch_des_monats.mkd" :target-dir (io/file "public" "book-covers")}) (defn imgurl->bytes [lovelybooks-url] @@ -39,9 +39,27 @@ (defn find-missing-covers [books-url target-dir] (remove #(fs/exists? (url->file % target-dir)) (scrape-book-urls books-url))) - + +(html/defsnippet cover-item-model "buchdesmonats/layout.html" [:div#covers :> :div] + [link title] + [:a] (html/set-attr :href link) + [:img] (html/set-attr :src (url->file link "book-covers") :title title)) + +(html/deftemplate index-template "buchdesmonats/layout.html" + [cover-urls] + [:#covers] (html/content (map + #(cover-item-model % "To LovelyBooks") + cover-urls))) + +(defn generate-html [book-urls target-dir] + (let [content (apply str (index-template book-urls))] + (with-open [out (io/writer (io/file "public" "index.html"))] + (.write out content)))) + (defn -main [& args] - (fs/mkdirs (:target-dir config)) - (doall (pmap #(scrape-book-cover % (:target-dir config)) - (find-missing-covers (:books-url config) (:target-dir config)))) + (fs/mkdirs (:target-dir *config*)) + ;;; TODO: refactor the whole config shit + (generate-html (scrape-book-urls (:books-url *config*)) "public") + (doall (pmap #(scrape-book-cover % (:target-dir *config*)) + (find-missing-covers (:books-url *config*) (:target-dir *config*)))) true)