From bc62c8a790558142f64c55287ce2449abd1372ed Mon Sep 17 00:00:00 2001 From: Albert Lai Date: Sun, 14 Jun 2015 13:47:18 +0800 Subject: [PATCH 1/2] fix issue #24 image handling in Post is generally broken --- src/cryogen_core/compiler.clj | 14 +++++++++++--- src/cryogen_core/io.clj | 6 +----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 155e774..2934121 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -1,8 +1,7 @@ (ns cryogen-core.compiler (:require [selmer.parser :refer [cache-off! render-file]] [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]] @@ -263,6 +262,15 @@ [posts config] (map #(update-in % [:tags] (partial map (partial tag-info config))) posts)) +(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" [] @@ -311,7 +319,7 @@ (wipe-public-folder keep-files) (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) diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index 53cad2c..66b92f8 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -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"))) From 7c443a8b5caf2051ffe7eadc0e98750e36657156 Mon Sep 17 00:00:00 2001 From: Albert Lai Date: Sun, 14 Jun 2015 18:23:58 +0800 Subject: [PATCH 2/2] add experimental theme support --- src/cryogen_core/compiler.clj | 27 +++++++++++++++++++++------ src/cryogen_core/io.clj | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 155e774..b5db392 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -1,5 +1,6 @@ (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]] @@ -196,7 +197,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 +212,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 +229,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 +241,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 +253,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 +264,16 @@ [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 read-config "Reads the config file" [] @@ -306,9 +317,13 @@ :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) diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index 53cad2c..cdb469d 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -62,7 +62,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")))