Cleanup + fixes for config based themes

This commit is contained in:
lacarmen 2015-06-14 11:16:35 -04:00
parent fa07db5a4b
commit 4511536cc9
3 changed files with 23 additions and 27 deletions

View file

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

View file

@ -2,7 +2,8 @@
(:require [selmer.parser :refer [cache-off! render-file]] (:require [selmer.parser :refer [cache-off! render-file]]
[selmer.util :refer [set-custom-resource-path!]] [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-resources-from-theme]]
[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]]
@ -28,11 +29,6 @@
[ext] [ext]
(re-pattern (str (s/replace ext "." "\\.") "$"))) (re-pattern (str (s/replace ext "." "\\.") "$")))
(defn find-md-assets
"Returns a list of files ending with .md under templates"
[ignored-files]
(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 ignored-files]} mu] [{:keys [post-root ignored-files]} mu]
@ -111,8 +107,7 @@
:formatted-archive-group formatted-group :formatted-archive-group formatted-group
:parsed-archive-group (.parse archive-fmt formatted-group) :parsed-archive-group (.parse archive-fmt formatted-group)
:uri (post-uri file-name config markup) :uri (post-uri file-name config markup)
:tags (set (:tags page-meta))}) :tags (set (:tags page-meta))}))))
)))
(defn read-posts (defn read-posts
"Returns a sequence of maps representing the data from markdown files of posts. "Returns a sequence of maps representing the data from markdown files of posts.
@ -196,7 +191,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 "page.html" (render-file "/html/page.html"
(merge params (merge params
{:servlet-context "../" {:servlet-context "../"
:page page :page page
@ -211,7 +206,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 (:layout post)) (render-file (str "/html/" (:layout post))
(merge params (merge params
{:servlet-context "../" {:servlet-context "../"
:post post :post post
@ -228,7 +223,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 "tag.html" (render-file "/html/tag.html"
(merge params (merge params
{:servlet-context "../" {:servlet-context "../"
:name name :name name
@ -240,7 +235,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 "home.html" (render-file "/html/home.html"
(merge params (merge params
{:home true {:home true
:disqus? disqus? :disqus? disqus?
@ -252,7 +247,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 "archives.html" (render-file "/html/archives.html"
(merge params (merge params
{:archives true {:archives true
:groups (group-for-archive posts) :groups (group-for-archive posts)
@ -263,16 +258,7 @@
[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 (defn copy-resources-from-markup-folders
"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" "Copy resources from markup folders"
[config] [config]
(copy-resources (copy-resources
@ -325,15 +311,15 @@
: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/")})] :theme-path (str "file:resources/templates/themes/" (:theme config))})]
(set-custom-resource-path! (:site-theme-path params)) (set-custom-resource-path! (:theme-path params))
(wipe-public-folder keep-files) (wipe-public-folder keep-files)
(println (blue "copying theme resources")) (println (blue "copying theme resources"))
(copy-resources-from-theme config) (copy-resources-from-theme config)
(println (blue "copying resources")) (println (blue "copying resources"))
(copy-resources config) (copy-resources config)
(copy-resoures-from-markup-folders config) (copy-resources-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

@ -66,3 +66,13 @@
(copy-dir src target ignored-files) (copy-dir src target ignored-files)
:else :else
(fs/copy src target))))) (fs/copy src target)))))
(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")
(str theme-path "/html/404.html")]}))))