From bc62c8a790558142f64c55287ce2449abd1372ed Mon Sep 17 00:00:00 2001 From: Albert Lai Date: Sun, 14 Jun 2015 13:47:18 +0800 Subject: [PATCH] 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")))