fix issue #24 image handling in Post is generally broken

This commit is contained in:
Albert Lai 2015-06-14 13:47:18 +08:00
parent 717b2dc370
commit bc62c8a790
2 changed files with 12 additions and 8 deletions

View file

@ -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)

View file

@ -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")))