Merge pull request #26 from zerg000000/config-based-theme
Config based theme
This commit is contained in:
commit
fa07db5a4b
2 changed files with 32 additions and 14 deletions
|
@ -1,8 +1,8 @@
|
|||
(ns cryogen-core.compiler
|
||||
(:require [selmer.parser :refer [cache-off! render-file]]
|
||||
[selmer.util :refer [set-custom-resource-path!]]
|
||||
[cryogen-core.io :refer
|
||||
[get-resource find-assets create-folder wipe-public-folder copy-resources
|
||||
copy-images-from-markdown-folders]]
|
||||
[get-resource find-assets create-folder wipe-public-folder copy-resources]]
|
||||
[cryogen-core.sitemap :as sitemap]
|
||||
[cryogen-core.rss :as rss]
|
||||
[io.aviso.exception :refer [write-exception]]
|
||||
|
@ -196,7 +196,7 @@
|
|||
(doseq [{:keys [uri] :as page} pages]
|
||||
(println "\t-->" (cyan uri))
|
||||
(spit (str public uri)
|
||||
(render-file "templates/html/layouts/page.html"
|
||||
(render-file "page.html"
|
||||
(merge params
|
||||
{:servlet-context "../"
|
||||
:page page
|
||||
|
@ -211,7 +211,7 @@
|
|||
(doseq [post posts]
|
||||
(println "\t-->" (cyan (:uri post)))
|
||||
(spit (str public (:uri post))
|
||||
(render-file (str "templates/html/layouts/" (:layout post))
|
||||
(render-file (str (:layout post))
|
||||
(merge params
|
||||
{:servlet-context "../"
|
||||
:post post
|
||||
|
@ -228,7 +228,7 @@
|
|||
(let [{:keys [name uri]} (tag-info params tag)]
|
||||
(println "\t-->" (cyan uri))
|
||||
(spit (str public uri)
|
||||
(render-file "templates/html/layouts/tag.html"
|
||||
(render-file "tag.html"
|
||||
(merge params
|
||||
{:servlet-context "../"
|
||||
:name name
|
||||
|
@ -240,7 +240,7 @@
|
|||
[{:keys [blog-prefix disqus?] :as params}]
|
||||
(println (blue "compiling index"))
|
||||
(spit (str public blog-prefix "/index.html")
|
||||
(render-file "templates/html/layouts/home.html"
|
||||
(render-file "home.html"
|
||||
(merge params
|
||||
{:home true
|
||||
:disqus? disqus?
|
||||
|
@ -252,7 +252,7 @@
|
|||
[{:keys [blog-prefix] :as params} posts]
|
||||
(println (blue "compiling archives"))
|
||||
(spit (str public blog-prefix "/archives.html")
|
||||
(render-file "templates/html/layouts/archives.html"
|
||||
(render-file "archives.html"
|
||||
(merge params
|
||||
{:archives true
|
||||
:groups (group-for-archive posts)
|
||||
|
@ -263,6 +263,24 @@
|
|||
[posts config]
|
||||
(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
|
||||
"Reads the config file"
|
||||
[]
|
||||
|
@ -306,12 +324,16 @@
|
|||
:archives-uri (str blog-prefix "/archives.html")
|
||||
:index-uri (str blog-prefix "/index.html")
|
||||
: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)
|
||||
(println (blue "copying theme resources"))
|
||||
(copy-resources-from-theme config)
|
||||
(println (blue "copying resources"))
|
||||
(copy-resources config)
|
||||
(copy-images-from-markdown-folders config)
|
||||
(copy-resoures-from-markup-folders config)
|
||||
(compile-pages params pages)
|
||||
(compile-posts params posts)
|
||||
(compile-tags params posts-by-tag)
|
||||
|
|
|
@ -45,10 +45,6 @@
|
|||
(doseq [path (.listFiles (io/file public) filenamefilter)]
|
||||
(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]
|
||||
(fs/mkdirs target)
|
||||
(let [filename-filter (apply reject-re-filter ignored-files)
|
||||
|
@ -62,7 +58,7 @@
|
|||
(defn copy-resources [{:keys [blog-prefix resources ignored-files]}]
|
||||
(doseq [resource resources]
|
||||
(let [src (str "resources/templates/" resource)
|
||||
target (str public blog-prefix "/" resource)]
|
||||
target (str public blog-prefix "/" (fs/base-name resource))]
|
||||
(cond
|
||||
(not (.exists (io/file src)))
|
||||
(throw (IllegalArgumentException. (str "resource " src " not found")))
|
||||
|
|
Loading…
Reference in a new issue