Support :ignored-file config key

Prevent the compiler attempting to process files defined by a list of
regexps. By default ignore emacs and vi backup files.
master
J Irving 10 years ago
parent a49bda02bc
commit efbe831261

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

@ -26,18 +26,18 @@
(defn find-md-assets
"Returns a list of files ending with .md under templates"
[]
(find-assets "templates" ".md"))
[ignored-files]
(find-assets "templates" ".md" ignored-files))
(defn find-posts
"Returns a list of markdown files representing posts under the post root in templates/md"
[{:keys [post-root]}]
(find-assets (str "templates/md" post-root) ".md"))
[{:keys [post-root ignored-files]}]
(find-assets (str "templates/md" post-root) ".md" ignored-files))
(defn find-pages
"Returns a list of markdown files representing pages under the page root in templates/md"
[{:keys [page-root]}]
(find-assets (str "templates/md" page-root) ".md"))
[{:keys [page-root ignored-files]}]
(find-assets (str "templates/md" page-root) ".md" ignored-files))
(defn parse-post-date
"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-dest] (fnil str "css"))
(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)
blog-prefix (:blog-prefix config)]
(merge
@ -272,7 +273,7 @@
"Generates all the html and copies over resources specified in the config"
[]
(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))
pages (add-prev-next (read-pages config))
[navbar-pages sidebar-pages] (group-pages pages)
@ -297,7 +298,7 @@
(compile-index default-params config)
(compile-archives default-params posts config)
(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"))
(spit (str public blog-prefix "/" rss-name) (rss/make-channel config posts))
(println (blue "compiling sass"))

@ -11,9 +11,16 @@
(.toURI)
(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)
file-seq
(filter (ignore ignored-files))
(filter (fn [file] (-> file .getName (.endsWith ext))))))
(defn create-folder [folder]

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

@ -1,21 +1,26 @@
(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]
(file-seq (file root)))
(defn get-assets [root ignored-files]
(->> root
file
file-seq
(filter #(not (.isDirectory %)))
(filter (ignore ignored-files))))
(defn sum-times [path]
(->> (get-assets path) (map #(.lastModified %)) (reduce +)))
(defn sum-times [path ignored-files]
(->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
(defn watch-assets [root action]
(loop [times (sum-times root)]
(defn watch-assets [root ignored-files action]
(loop [times (sum-times root ignored-files)]
(Thread/sleep 300)
(let [new-times (sum-times root)]
(let [new-times (sum-times root ignored-files)]
(when-not (= times new-times)
(action))
(recur new-times))))
(defn start-watcher! [root action]
(doto (Thread. #(watch-assets root action))
(defn start-watcher! [root ignored-files action]
(doto (Thread. #(watch-assets root ignored-files action))
(.setDaemon true)
(.start)))

Loading…
Cancel
Save