From d9fe01d8f603354f907b89d2662b05f497b8c2bb Mon Sep 17 00:00:00 2001 From: Martin Kremers Date: Fri, 5 Dec 2014 18:17:44 +0100 Subject: [PATCH] Make images from md folders available, so a post or page can be one unit in a folder --- src/cryogen_core/compiler.clj | 4 +++- src/cryogen_core/io.clj | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 1dc189c..5ec9d0e 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -1,7 +1,8 @@ (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]] + [get-resource find-assets create-folder wipe-public-folder copy-resources + copy-images-from-markdown-folders]] [cryogen-core.sitemap :as sitemap] [cryogen-core.rss :as rss] [io.aviso.exception :refer [write-exception]] @@ -288,6 +289,7 @@ (wipe-public-folder keep-files) (println (blue "copying resources")) (copy-resources config) + (copy-images-from-markdown-folders config) (compile-pages default-params pages config) (compile-posts default-params posts config) (compile-tags default-params posts-by-tag config) diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index 6bfc052..095aae5 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -1,6 +1,7 @@ (ns cryogen-core.io (:require [clojure.java.io :refer [file]] - [me.raynes.fs :as fs])) + [me.raynes.fs :as fs] + [clojure.java.io :as io])) (def public "resources/public") @@ -26,6 +27,11 @@ (doseq [path (.listFiles (file public) filenamefilter)] (fs/delete-dir path)))) +(defn copy-images-from-markdown-folders [{:keys [blog-prefix]}] + (let [blog-prefix-relative (if (= \/ (first blog-prefix)) (subs blog-prefix 1) blog-prefix)] + (doseq [asset (fs/find-files "resources/templates" #".+(jpg|jpeg|png|gif)")] + (fs/copy asset (io/file public blog-prefix-relative "img" (.getName asset)))))) + (defn copy-resources [{:keys [blog-prefix resources]}] (doseq [resource resources] (let [src (str "resources/templates/" resource)