Layout works now
This commit is contained in:
parent
e1d8943c96
commit
e3714f87ff
1 changed files with 23 additions and 5 deletions
|
@ -6,7 +6,7 @@
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[me.raynes.fs :as fs]))
|
[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")})
|
:target-dir (io/file "public" "book-covers")})
|
||||||
|
|
||||||
(defn imgurl->bytes [lovelybooks-url]
|
(defn imgurl->bytes [lovelybooks-url]
|
||||||
|
@ -39,9 +39,27 @@
|
||||||
(defn find-missing-covers [books-url target-dir]
|
(defn find-missing-covers [books-url target-dir]
|
||||||
(remove #(fs/exists? (url->file % target-dir))
|
(remove #(fs/exists? (url->file % target-dir))
|
||||||
(scrape-book-urls books-url)))
|
(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]
|
(defn -main [& args]
|
||||||
(fs/mkdirs (:target-dir config))
|
(fs/mkdirs (:target-dir *config*))
|
||||||
(doall (pmap #(scrape-book-cover % (:target-dir config))
|
;;; TODO: refactor the whole config shit
|
||||||
(find-missing-covers (:books-url config) (:target-dir config))))
|
(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)
|
true)
|
||||||
|
|
Loading…
Reference in a new issue