From 5c4d0d897a7312d52543d8faf1b8cf9bec457ff5 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Tue, 25 Mar 2014 23:41:56 +0100 Subject: [PATCH] Final polishing --- src/buchdesmonats/core.clj | 28 ++++++++++++++-------------- src/buchdesmonats/layout.html | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/buchdesmonats/layout.html diff --git a/src/buchdesmonats/core.clj b/src/buchdesmonats/core.clj index 3e7aeac..48dc736 100644 --- a/src/buchdesmonats/core.clj +++ b/src/buchdesmonats/core.clj @@ -6,9 +6,6 @@ [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" - :target-dir (io/file "public" "book-covers")}) - (defn imgurl->bytes [lovelybooks-url] (-> (java.net.URL. lovelybooks-url) html/html-resource @@ -21,8 +18,10 @@ (defn url->file [lovelybooks-url target-dir] (let [[_ author title] (re-find #".\/autor\/([^\/]+)\/(.+)-([0-9]+)-.\/$" lovelybooks-url)] - (io/file target-dir - (str/lower-case (str author "_" title ".jpg"))))) + (-> (str author "_" title ".jpg") + str/lower-case + (str/replace #"[^a-z0-9-_.]" "") + (#(io/file target-dir %))))) (defn scrape-book-urls [github-url] (->> (http-client/get github-url) @@ -47,9 +46,9 @@ (html/deftemplate index-template "buchdesmonats/layout.html" [cover-urls] - [:#covers] (html/content (map - #(cover-item-model % "To LovelyBooks") - cover-urls))) + [:#covers] (html/content + (map #(cover-item-model % "zu Lovely Books") + cover-urls))) (defn generate-html [book-urls target-dir] (let [content (apply str (index-template book-urls))] @@ -57,9 +56,10 @@ (.write out content)))) (defn -main [& args] - (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) + (let [github-url "https://raw.github.com/CTHN/wiki-data/master/pages/projects/buch_des_monats.mkd" + target-dir (io/file "public" "book-covers")] + (fs/mkdirs target-dir) + (generate-html (scrape-book-urls github-url) "public") + (doall (pmap #(scrape-book-cover % target-dir) + (find-missing-covers github-url target-dir))) + true)) diff --git a/src/buchdesmonats/layout.html b/src/buchdesmonats/layout.html new file mode 100644 index 0000000..476babd --- /dev/null +++ b/src/buchdesmonats/layout.html @@ -0,0 +1,30 @@ + + + + + cthn.de -- Buch des Monats + + + + + + +

Buch des Monats

+

Handerlesen und für gut befunden seit 2010 + von . Jeden Monat ein neues Buch aus seiner Sammlung zu den + Themengebieten Netzkultur, Geektum, Computerspiele und + Cyberpunk. Als CTHN-Projekt + begonnen ist diese Bücherliste mittlerweile Anlaufstelle für so manchen + Leser der nach neuem Stoff sucht. Die Buchcover stammen + von Lovely Books, der Code + von Aaron Mueller.

+ +
+
+ + LovelyBooks cover + +
+ +