Merge pull request #26 from zerg000000/config-based-theme

Config based theme
This commit is contained in:
Carmen La 2015-06-14 11:15:19 -04:00
commit fa07db5a4b
2 changed files with 32 additions and 14 deletions

View file

@ -1,8 +1,8 @@
(ns cryogen-core.compiler (ns cryogen-core.compiler
(:require [selmer.parser :refer [cache-off! render-file]] (:require [selmer.parser :refer [cache-off! render-file]]
[selmer.util :refer [set-custom-resource-path!]]
[cryogen-core.io :refer [cryogen-core.io :refer
[get-resource find-assets create-folder wipe-public-folder copy-resources [get-resource find-assets create-folder wipe-public-folder copy-resources]]
copy-images-from-markdown-folders]]
[cryogen-core.sitemap :as sitemap] [cryogen-core.sitemap :as sitemap]
[cryogen-core.rss :as rss] [cryogen-core.rss :as rss]
[io.aviso.exception :refer [write-exception]] [io.aviso.exception :refer [write-exception]]
@ -196,7 +196,7 @@
(doseq [{:keys [uri] :as page} pages] (doseq [{:keys [uri] :as page} pages]
(println "\t-->" (cyan uri)) (println "\t-->" (cyan uri))
(spit (str public uri) (spit (str public uri)
(render-file "templates/html/layouts/page.html" (render-file "page.html"
(merge params (merge params
{:servlet-context "../" {:servlet-context "../"
:page page :page page
@ -211,7 +211,7 @@
(doseq [post posts] (doseq [post posts]
(println "\t-->" (cyan (:uri post))) (println "\t-->" (cyan (:uri post)))
(spit (str public (:uri post)) (spit (str public (:uri post))
(render-file (str "templates/html/layouts/" (:layout post)) (render-file (str (:layout post))
(merge params (merge params
{:servlet-context "../" {:servlet-context "../"
:post post :post post
@ -228,7 +228,7 @@
(let [{:keys [name uri]} (tag-info params tag)] (let [{:keys [name uri]} (tag-info params tag)]
(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 "tag.html"
(merge params (merge params
{:servlet-context "../" {:servlet-context "../"
:name name :name name
@ -240,7 +240,7 @@
[{:keys [blog-prefix disqus?] :as params}] [{:keys [blog-prefix disqus?] :as params}]
(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 "home.html"
(merge params (merge params
{:home true {:home true
:disqus? disqus? :disqus? disqus?
@ -252,7 +252,7 @@
[{:keys [blog-prefix] :as params} posts] [{:keys [blog-prefix] :as params} posts]
(println (blue "compiling archives")) (println (blue "compiling archives"))
(spit (str public blog-prefix "/archives.html") (spit (str public blog-prefix "/archives.html")
(render-file "templates/html/layouts/archives.html" (render-file "archives.html"
(merge params (merge params
{:archives true {:archives true
:groups (group-for-archive posts) :groups (group-for-archive posts)
@ -263,6 +263,24 @@
[posts config] [posts config]
(map #(update-in % [:tags] (partial map (partial tag-info config))) posts)) (map #(update-in % [:tags] (partial map (partial tag-info config))) posts))
(defn copy-resources-from-theme
"Copy resources from theme"
[config]
(let [theme-path (str "themes/" (:theme config))]
(copy-resources
(merge config
{:resources [(str theme-path "/css")
(str theme-path "/js")]}))))
(defn copy-resoures-from-markup-folders
"Copy resources from markup folders"
[config]
(copy-resources
(merge config
{:resources (for [mu (m/markups)
t ["posts" "pages"]] (str (m/dir mu) "/" t))
:ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))})))
(defn read-config (defn read-config
"Reads the config file" "Reads the config file"
[] []
@ -306,12 +324,16 @@
: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)})] :site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)
:site-theme-path (str "file:resources/templates/themes/" (:theme config) "/html/layouts/")})]
(set-custom-resource-path! (:site-theme-path params))
(wipe-public-folder keep-files) (wipe-public-folder keep-files)
(println (blue "copying theme resources"))
(copy-resources-from-theme config)
(println (blue "copying resources")) (println (blue "copying resources"))
(copy-resources config) (copy-resources config)
(copy-images-from-markdown-folders config) (copy-resoures-from-markup-folders config)
(compile-pages params pages) (compile-pages params pages)
(compile-posts params posts) (compile-posts params posts)
(compile-tags params posts-by-tag) (compile-tags params posts-by-tag)

View file

@ -45,10 +45,6 @@
(doseq [path (.listFiles (io/file public) filenamefilter)] (doseq [path (.listFiles (io/file public) filenamefilter)]
(fs/delete-dir path)))) (fs/delete-dir path))))
(defn copy-images-from-markdown-folders [{:keys [blog-prefix]}]
(doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")]
(io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset))))))
(defn copy-dir [src target ignored-files] (defn copy-dir [src target ignored-files]
(fs/mkdirs target) (fs/mkdirs target)
(let [filename-filter (apply reject-re-filter ignored-files) (let [filename-filter (apply reject-re-filter ignored-files)
@ -62,7 +58,7 @@
(defn copy-resources [{:keys [blog-prefix resources ignored-files]}] (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 "/" (fs/base-name resource))]
(cond (cond
(not (.exists (io/file src))) (not (.exists (io/file src)))
(throw (IllegalArgumentException. (str "resource " src " not found"))) (throw (IllegalArgumentException. (str "resource " src " not found")))