Merge pull request #4 from j0ni/ignore-backup-files

Support :ignored-file config key
master
Carmen La 10 years ago
commit aced19ce2a

@ -1,4 +1,4 @@
(defproject cryogen-core "0.1.8" (defproject cryogen-core "0.1.9-SNAPSHOT"
:description "Cryogen's compiler" :description "Cryogen's compiler"
:url "https://github.com/lacarmen/cryogen-core" :url "https://github.com/lacarmen/cryogen-core"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"

@ -26,18 +26,18 @@
(defn find-md-assets (defn find-md-assets
"Returns a list of files ending with .md under templates" "Returns a list of files ending with .md under templates"
[] [ignored-files]
(find-assets "templates" ".md")) (find-assets "templates" ".md" ignored-files))
(defn find-posts (defn find-posts
"Returns a list of markdown files representing posts under the post root in templates/md" "Returns a list of markdown files representing posts under the post root in templates/md"
[{:keys [post-root]}] [{:keys [post-root ignored-files]}]
(find-assets (str "templates/md" post-root) ".md")) (find-assets (str "templates/md" post-root) ".md" ignored-files))
(defn find-pages (defn find-pages
"Returns a list of markdown files representing pages under the page root in templates/md" "Returns a list of markdown files representing pages under the page root in templates/md"
[{:keys [page-root]}] [{:keys [page-root ignored-files]}]
(find-assets (str "templates/md" page-root) ".md")) (find-assets (str "templates/md" page-root) ".md" ignored-files))
(defn parse-post-date (defn parse-post-date
"Parses the post date from the post's file name and returns the corresponding java date object" "Parses the post date from the post's file name and returns the corresponding java date object"
@ -257,7 +257,8 @@
(update-in [:sass-src] (fnil str "css")) (update-in [:sass-src] (fnil str "css"))
(update-in [:sass-dest] (fnil str "css")) (update-in [:sass-dest] (fnil str "css"))
(update-in [:post-date-format] (fnil str "yyyy-MM-dd")) (update-in [:post-date-format] (fnil str "yyyy-MM-dd"))
(update-in [:keep-files] (fnil seq []))) (update-in [:keep-files] (fnil seq []))
(update-in [:ignored-files] (fnil seq [#"^\.#.*" #".*\.swp$"])))
site-url (:site-url config) site-url (:site-url config)
blog-prefix (:blog-prefix config)] blog-prefix (:blog-prefix config)]
(merge (merge
@ -272,7 +273,7 @@
"Generates all the html and copies over resources specified in the config" "Generates all the html and copies over resources specified in the config"
[] []
(println (green "compiling assets...")) (println (green "compiling assets..."))
(let [{:keys [site-url blog-prefix rss-name recent-posts sass-src sass-dest keep-files] :as config} (read-config) (let [{:keys [site-url blog-prefix rss-name recent-posts sass-src sass-dest keep-files ignored-files] :as config} (read-config)
posts (add-prev-next (read-posts config)) posts (add-prev-next (read-posts config))
pages (add-prev-next (read-pages config)) pages (add-prev-next (read-pages config))
[navbar-pages sidebar-pages] (group-pages pages) [navbar-pages sidebar-pages] (group-pages pages)
@ -297,7 +298,7 @@
(compile-index default-params config) (compile-index default-params config)
(compile-archives default-params posts config) (compile-archives default-params posts config)
(println (blue "generating site map")) (println (blue "generating site map"))
(spit (str public blog-prefix "/sitemap.xml") (sitemap/generate site-url)) (spit (str public blog-prefix "/sitemap.xml") (sitemap/generate site-url ignored-files))
(println (blue "generating rss")) (println (blue "generating rss"))
(spit (str public blog-prefix "/" rss-name) (rss/make-channel config posts)) (spit (str public blog-prefix "/" rss-name) (rss/make-channel config posts))
(println (blue "compiling sass")) (println (blue "compiling sass"))

@ -11,9 +11,16 @@
(.toURI) (.toURI)
(io/file))) (io/file)))
(defn find-assets [f ext] (defn ignore [ignored-files]
(fn [file]
(let [name (.getName file)
matches (map #(re-find % name) ignored-files)]
(not (some seq matches)))))
(defn find-assets [f ext ignored-files]
(->> (get-resource f) (->> (get-resource f)
file-seq file-seq
(filter (ignore ignored-files))
(filter (fn [file] (-> file .getName (.endsWith ext)))))) (filter (fn [file] (-> file .getName (.endsWith ext))))))
(defn create-folder [folder] (defn create-folder [folder]

@ -13,13 +13,13 @@
(defn loc [f] (defn loc [f]
(-> f (.getAbsolutePath) (.split "resources/public/") second)) (-> f (.getAbsolutePath) (.split "resources/public/") second))
(defn generate [site-url] (defn generate [site-url ignored-files]
(with-out-str (with-out-str
(emit (emit
{:tag :urlset {:tag :urlset
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"} :attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
:content :content
(for [f (find-assets "public" ".html")] (for [f (find-assets "public" ".html" ignored-files)]
{:tag :url {:tag :url
:content :content
[{:tag :loc [{:tag :loc

@ -1,21 +1,26 @@
(ns cryogen-core.watcher (ns cryogen-core.watcher
(:require [clojure.java.io :refer [file]])) (:require [clojure.java.io :refer [file]]
[cryogen-core.io :refer [ignore]]))
(defn get-assets [root] (defn get-assets [root ignored-files]
(file-seq (file root))) (->> root
file
file-seq
(filter #(not (.isDirectory %)))
(filter (ignore ignored-files))))
(defn sum-times [path] (defn sum-times [path ignored-files]
(->> (get-assets path) (map #(.lastModified %)) (reduce +))) (->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
(defn watch-assets [root action] (defn watch-assets [root ignored-files action]
(loop [times (sum-times root)] (loop [times (sum-times root ignored-files)]
(Thread/sleep 300) (Thread/sleep 300)
(let [new-times (sum-times root)] (let [new-times (sum-times root ignored-files)]
(when-not (= times new-times) (when-not (= times new-times)
(action)) (action))
(recur new-times)))) (recur new-times))))
(defn start-watcher! [root action] (defn start-watcher! [root ignored-files action]
(doto (Thread. #(watch-assets root action)) (doto (Thread. #(watch-assets root ignored-files action))
(.setDaemon true) (.setDaemon true)
(.start))) (.start)))

Loading…
Cancel
Save