Merge branch 'master' into add-asciidoc-support
Conflicts: project.clj
This commit is contained in:
commit
cb18e5734d
6 changed files with 108 additions and 69 deletions
|
@ -1,4 +1,4 @@
|
||||||
(defproject cryogen-core "0.1.9"
|
(defproject cryogen-core "0.1.14"
|
||||||
: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"
|
||||||
|
@ -12,6 +12,6 @@
|
||||||
[io.aviso/pretty "0.1.13"]
|
[io.aviso/pretty "0.1.13"]
|
||||||
[hiccup "1.0.5"]
|
[hiccup "1.0.5"]
|
||||||
[selmer "0.7.8"]
|
[selmer "0.7.8"]
|
||||||
[markdown-clj "0.9.60"
|
[markdown-clj "0.9.62"]
|
||||||
:exclusions [com.keminglabs/cljx]]
|
[pandect "0.4.1"]
|
||||||
[org.asciidoctor/asciidoctorj "1.5.2"]])
|
[org.asciidoctor/asciidoctorj "1.5.2"]])
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
|
|
||||||
(defn compile-pages
|
(defn compile-pages
|
||||||
"Compiles all the pages into html and spits them out into the public folder"
|
"Compiles all the pages into html and spits them out into the public folder"
|
||||||
[default-params pages {:keys [blog-prefix page-root asset-url]}]
|
[default-params pages {:keys [blog-prefix page-root]}]
|
||||||
(when-not (empty? pages)
|
(when-not (empty? pages)
|
||||||
(println (blue "compiling pages"))
|
(println (blue "compiling pages"))
|
||||||
(create-folder (str blog-prefix page-root))
|
(create-folder (str blog-prefix page-root))
|
||||||
|
@ -195,11 +195,11 @@
|
||||||
(merge default-params
|
(merge default-params
|
||||||
{:servlet-context "../"
|
{:servlet-context "../"
|
||||||
:page page
|
:page page
|
||||||
:asset-url asset-url}))))))
|
:uri uri}))))))
|
||||||
|
|
||||||
(defn compile-posts
|
(defn compile-posts
|
||||||
"Compiles all the posts into html and spits them out into the public folder"
|
"Compiles all the posts into html and spits them out into the public folder"
|
||||||
[default-params posts {:keys [blog-prefix post-root disqus-shortname asset-url]}]
|
[default-params posts {:keys [blog-prefix post-root disqus-shortname]}]
|
||||||
(when-not (empty? posts)
|
(when-not (empty? posts)
|
||||||
(println (blue "compiling posts"))
|
(println (blue "compiling posts"))
|
||||||
(create-folder (str blog-prefix post-root))
|
(create-folder (str blog-prefix post-root))
|
||||||
|
@ -211,7 +211,7 @@
|
||||||
{:servlet-context "../"
|
{:servlet-context "../"
|
||||||
:post post
|
:post post
|
||||||
:disqus-shortname disqus-shortname
|
:disqus-shortname disqus-shortname
|
||||||
:asset-url asset-url}))))))
|
:uri (:uri post)}))))))
|
||||||
|
|
||||||
(defn compile-tags
|
(defn compile-tags
|
||||||
"Compiles all the tag pages into html and spits them out into the public folder"
|
"Compiles all the tag pages into html and spits them out into the public folder"
|
||||||
|
@ -224,13 +224,15 @@
|
||||||
(println "\t-->" (cyan uri))
|
(println "\t-->" (cyan uri))
|
||||||
(spit (str public uri)
|
(spit (str public uri)
|
||||||
(render-file "templates/html/layouts/tag.html"
|
(render-file "templates/html/layouts/tag.html"
|
||||||
(merge default-params {:servlet-context "../"
|
(merge default-params
|
||||||
|
{:servlet-context "../"
|
||||||
:name name
|
:name name
|
||||||
:posts posts})))))))
|
:posts posts
|
||||||
|
:uri uri})))))))
|
||||||
|
|
||||||
(defn compile-index
|
(defn compile-index
|
||||||
"Compiles the index page into html and spits it out into the public folder"
|
"Compiles the index page into html and spits it out into the public folder"
|
||||||
[default-params {:keys [blog-prefix disqus? asset-url]}]
|
[default-params {:keys [blog-prefix disqus?]}]
|
||||||
(println (blue "compiling index"))
|
(println (blue "compiling index"))
|
||||||
(spit (str public blog-prefix "/index.html")
|
(spit (str public blog-prefix "/index.html")
|
||||||
(render-file "templates/html/layouts/home.html"
|
(render-file "templates/html/layouts/home.html"
|
||||||
|
@ -238,7 +240,7 @@
|
||||||
{:home true
|
{:home true
|
||||||
:disqus? disqus?
|
:disqus? disqus?
|
||||||
:post (get-in default-params [:latest-posts 0])
|
:post (get-in default-params [:latest-posts 0])
|
||||||
:asset-url asset-url}))))
|
:uri (str blog-prefix "/index.html")}))))
|
||||||
|
|
||||||
(defn compile-archives
|
(defn compile-archives
|
||||||
"Compiles the archives page into html and spits it out into the public folder"
|
"Compiles the archives page into html and spits it out into the public folder"
|
||||||
|
@ -248,7 +250,8 @@
|
||||||
(render-file "templates/html/layouts/archives.html"
|
(render-file "templates/html/layouts/archives.html"
|
||||||
(merge default-params
|
(merge default-params
|
||||||
{:archives true
|
{:archives true
|
||||||
:groups (group-for-archive posts)}))))
|
:groups (group-for-archive posts)
|
||||||
|
:uri (str blog-prefix "/archives.html")}))))
|
||||||
|
|
||||||
(defn tag-posts
|
(defn tag-posts
|
||||||
"Converts the tags in each post into links"
|
"Converts the tags in each post into links"
|
||||||
|
@ -264,20 +267,17 @@
|
||||||
read-string
|
read-string
|
||||||
(update-in [:blog-prefix] (fnil str ""))
|
(update-in [:blog-prefix] (fnil str ""))
|
||||||
(update-in [:rss-name] (fnil str "rss.xml"))
|
(update-in [:rss-name] (fnil str "rss.xml"))
|
||||||
|
(update-in [:rss-filters] (fnil seq []))
|
||||||
(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$"])))
|
(update-in [:ignored-files] (fnil seq [#"^\.#.*" #".*\.swp$"])))]
|
||||||
site-url (:site-url config)
|
|
||||||
blog-prefix (:blog-prefix config)]
|
|
||||||
(merge
|
(merge
|
||||||
config
|
config
|
||||||
{:page-root (root-path :page-root config)
|
{:page-root (root-path :page-root config)
|
||||||
:post-root (root-path :post-root config)
|
:post-root (root-path :post-root config)
|
||||||
:tag-root (root-path :tag-root config)
|
:tag-root (root-path :tag-root config)})))
|
||||||
:asset-root (str (if (.endsWith site-url "/") (apply str (butlast site-url)) site-url)
|
|
||||||
blog-prefix)})))
|
|
||||||
|
|
||||||
(defn compile-assets
|
(defn compile-assets
|
||||||
"Generates all the html and copies over resources specified in the config"
|
"Generates all the html and copies over resources specified in the config"
|
||||||
|
@ -296,7 +296,8 @@
|
||||||
:sidebar-pages sidebar-pages
|
:sidebar-pages sidebar-pages
|
||||||
:archives-uri (str blog-prefix "/archives.html")
|
:archives-uri (str blog-prefix "/archives.html")
|
||||||
:index-uri (str blog-prefix "/index.html")
|
:index-uri (str blog-prefix "/index.html")
|
||||||
:rss-uri (str blog-prefix "/" rss-name)}]
|
:rss-uri (str blog-prefix "/" rss-name)
|
||||||
|
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)}]
|
||||||
|
|
||||||
(wipe-public-folder keep-files)
|
(wipe-public-folder keep-files)
|
||||||
(println (blue "copying resources"))
|
(println (blue "copying resources"))
|
||||||
|
@ -309,20 +310,22 @@
|
||||||
(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 ignored-files))
|
(spit (str public blog-prefix "/sitemap.xml") (sitemap/generate site-url ignored-files))
|
||||||
(println (blue "generating rss"))
|
(println (blue "generating main 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 "generating filtered rss"))
|
||||||
|
(rss/make-filtered-channels public config posts-by-tag)
|
||||||
(println (blue "compiling sass"))
|
(println (blue "compiling sass"))
|
||||||
(sass/compile-sass->css!
|
(sass/compile-sass->css!
|
||||||
(str "resources/templates/" sass-src)
|
(str "resources/templates/" sass-src)
|
||||||
(str "resources/public" blog-prefix "/" sass-dest))))
|
(str "resources/public" blog-prefix "/" sass-dest)
|
||||||
|
ignored-files)))
|
||||||
|
|
||||||
(defn compile-assets-timed []
|
(defn compile-assets-timed []
|
||||||
(time
|
(time
|
||||||
(try
|
(try
|
||||||
(compile-assets)
|
(compile-assets)
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(if
|
(if (or (instance? IllegalArgumentException e)
|
||||||
(or (instance? IllegalArgumentException e)
|
|
||||||
(instance? clojure.lang.ExceptionInfo e))
|
(instance? clojure.lang.ExceptionInfo e))
|
||||||
(println (red "Error:") (yellow (.getMessage e)))
|
(println (red "Error:") (yellow (.getMessage e)))
|
||||||
(write-exception e))))))
|
(write-exception e))))))
|
||||||
|
|
|
@ -4,12 +4,17 @@
|
||||||
|
|
||||||
(def public "resources/public")
|
(def public "resources/public")
|
||||||
|
|
||||||
|
(defn re-filter [bool-fn re & other-res]
|
||||||
|
(let [res (conj other-res re)]
|
||||||
|
(reify java.io.FilenameFilter
|
||||||
|
(accept [this _ name]
|
||||||
|
(bool-fn (some #(re-find % name) res))))))
|
||||||
|
|
||||||
|
(def match-re-filter (partial re-filter some?))
|
||||||
|
(def reject-re-filter (partial re-filter nil?))
|
||||||
|
|
||||||
(defn get-resource [resource]
|
(defn get-resource [resource]
|
||||||
(-> (Thread/currentThread)
|
(-> resource io/resource io/file))
|
||||||
(.getContextClassLoader)
|
|
||||||
(.getResource resource)
|
|
||||||
(.toURI)
|
|
||||||
(io/file)))
|
|
||||||
|
|
||||||
(defn ignore [ignored-files]
|
(defn ignore [ignored-files]
|
||||||
(fn [file]
|
(fn [file]
|
||||||
|
@ -37,7 +42,17 @@
|
||||||
(doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")]
|
(doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")]
|
||||||
(io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset))))))
|
(io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset))))))
|
||||||
|
|
||||||
(defn copy-resources [{:keys [blog-prefix resources]}]
|
(defn copy-dir [src target ignored-files]
|
||||||
|
(fs/mkdirs target)
|
||||||
|
(let [filename-filter (apply reject-re-filter ignored-files)
|
||||||
|
files (.listFiles (io/file src) filename-filter)]
|
||||||
|
(doseq [f files]
|
||||||
|
(let [out (io/file target (.getName f))]
|
||||||
|
(if (.isDirectory f)
|
||||||
|
(copy-dir f out ignored-files)
|
||||||
|
(io/copy f out))))))
|
||||||
|
|
||||||
|
(defn copy-resources [{:keys [blog-prefix resources ignored-files]}]
|
||||||
(doseq [resource resources]
|
(doseq [resource resources]
|
||||||
(let [src (str "resources/templates/" resource)
|
(let [src (str "resources/templates/" resource)
|
||||||
target (str public blog-prefix "/" resource)]
|
target (str public blog-prefix "/" resource)]
|
||||||
|
@ -45,6 +60,6 @@
|
||||||
(not (.exists (io/file src)))
|
(not (.exists (io/file src)))
|
||||||
(throw (IllegalArgumentException. (str "resource " src " not found")))
|
(throw (IllegalArgumentException. (str "resource " src " not found")))
|
||||||
(.isDirectory (io/file src))
|
(.isDirectory (io/file src))
|
||||||
(fs/copy-dir src target)
|
(copy-dir src target ignored-files)
|
||||||
:else
|
:else
|
||||||
(fs/copy src target)))))
|
(fs/copy src target)))))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns cryogen-core.rss
|
(ns cryogen-core.rss
|
||||||
(:require [clj-rss.core :as rss]
|
(:require [clj-rss.core :as rss]
|
||||||
[clojure.xml :refer [emit]])
|
[clojure.xml :refer [emit]]
|
||||||
|
[text-decoration.core :refer :all])
|
||||||
(:import java.util.Date))
|
(:import java.util.Date))
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,3 +27,9 @@
|
||||||
:lastBuildDate (Date.)
|
:lastBuildDate (Date.)
|
||||||
:author (:author config)})
|
:author (:author config)})
|
||||||
(posts-to-items (:site-url config) (:author config) posts)))
|
(posts-to-items (:site-url config) (:author config) posts)))
|
||||||
|
|
||||||
|
(defn make-filtered-channels [public {:keys [rss-filters blog-prefix] :as config} posts-by-tag]
|
||||||
|
(doseq [filter rss-filters]
|
||||||
|
(let [uri (str public blog-prefix "/" (name filter) ".xml")]
|
||||||
|
(println "\t-->" (cyan uri))
|
||||||
|
(spit uri (make-channel config (get posts-by-tag filter))))))
|
|
@ -1,6 +1,7 @@
|
||||||
(ns cryogen-core.sass
|
(ns cryogen-core.sass
|
||||||
(:require [clojure.java.shell :refer [sh]]
|
(:require [clojure.java.shell :refer [sh]]
|
||||||
[clojure.java.io :as io]))
|
[clojure.java.io :as io]
|
||||||
|
[cryogen-core.io :refer [ignore match-re-filter]]))
|
||||||
|
|
||||||
(defn sass-installed?
|
(defn sass-installed?
|
||||||
"Checks for the installation of Sass."
|
"Checks for the installation of Sass."
|
||||||
|
@ -8,11 +9,14 @@
|
||||||
(= 0 (:exit (sh "sass" "--version"))))
|
(= 0 (:exit (sh "sass" "--version"))))
|
||||||
|
|
||||||
(defn find-sass-files
|
(defn find-sass-files
|
||||||
"Given a Diretory, gets files, filtered to those having scss or sass extention"
|
"Given a Diretory, gets files, Filtered to those having scss or sass
|
||||||
[dir]
|
extention. Ignores files matching any ignored regexps."
|
||||||
(->> (.list (io/file dir))
|
[dir ignored-files]
|
||||||
(seq)
|
(let [filename-filter (match-re-filter #"(?i:s[ca]ss$)")]
|
||||||
(filter (comp not nil? (partial re-find #"(?i:s[ca]ss$)")))))
|
(->> (.listFiles (io/file dir) filename-filter)
|
||||||
|
(filter #(not (.isDirectory %)))
|
||||||
|
(filter (ignore ignored-files))
|
||||||
|
(map #(.getName %)))))
|
||||||
|
|
||||||
(defn compile-sass-file!
|
(defn compile-sass-file!
|
||||||
"Given a sass file which might be in src-sass directory,
|
"Given a sass file which might be in src-sass directory,
|
||||||
|
@ -31,8 +35,9 @@
|
||||||
dest-sass. Prompts you to install sass if he finds sass files and can't find
|
dest-sass. Prompts you to install sass if he finds sass files and can't find
|
||||||
the command. Shows you any problems it comes across when compiling. "
|
the command. Shows you any problems it comes across when compiling. "
|
||||||
[src-sass
|
[src-sass
|
||||||
dest-sass]
|
dest-sass
|
||||||
(let [sass-files (find-sass-files src-sass)]
|
ignored-files]
|
||||||
|
(let [sass-files (find-sass-files src-sass ignored-files)]
|
||||||
(if (seq sass-files)
|
(if (seq sass-files)
|
||||||
;; I found sass files,
|
;; I found sass files,
|
||||||
;; If sass is installed
|
;; If sass is installed
|
||||||
|
|
|
@ -1,24 +1,33 @@
|
||||||
(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]]))
|
[cryogen-core.io :refer [ignore]]
|
||||||
|
[pandect.core :refer [md5]]
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(defn get-assets [root ignored-files]
|
(defn get-assets [path ignored-files]
|
||||||
(->> root
|
(->> path
|
||||||
file
|
file
|
||||||
file-seq
|
file-seq
|
||||||
(filter #(not (.isDirectory %)))
|
(filter #(not (.isDirectory %)))
|
||||||
(filter (ignore ignored-files))))
|
(filter (ignore ignored-files))))
|
||||||
|
|
||||||
(defn sum-times [path ignored-files]
|
(defn checksums [path ignored-files]
|
||||||
(->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
|
(let [files (get-assets path ignored-files)]
|
||||||
|
(zipmap (map md5 files) files)))
|
||||||
|
|
||||||
|
(defn find-changes [old-sums new-sums]
|
||||||
|
(let [old-sum-set (-> old-sums keys set)
|
||||||
|
new-sum-set (-> new-sums keys set)]
|
||||||
|
(when-some [changes (set/difference new-sum-set old-sum-set)]
|
||||||
|
(vals (select-keys new-sums changes)))))
|
||||||
|
|
||||||
(defn watch-assets [root ignored-files action]
|
(defn watch-assets [root ignored-files action]
|
||||||
(loop [times (sum-times root ignored-files)]
|
(loop [sums (checksums root ignored-files)]
|
||||||
(Thread/sleep 300)
|
(Thread/sleep 300)
|
||||||
(let [new-times (sum-times root ignored-files)]
|
(let [new-sums (checksums root ignored-files)]
|
||||||
(when-not (= times new-times)
|
(when (find-changes sums new-sums)
|
||||||
(action))
|
(action))
|
||||||
(recur new-times))))
|
(recur new-sums))))
|
||||||
|
|
||||||
(defn start-watcher! [root ignored-files action]
|
(defn start-watcher! [root ignored-files action]
|
||||||
(doto (Thread. #(watch-assets root ignored-files action))
|
(doto (Thread. #(watch-assets root ignored-files action))
|
||||||
|
|
Loading…
Reference in a new issue