From 02635f26eaf5f2fdac96b83cdd884eb662a7923d Mon Sep 17 00:00:00 2001 From: Anton Podviaznikov Date: Fri, 15 Jan 2016 23:53:25 -0800 Subject: [PATCH 1/2] start work on images task --- src/io/perun.clj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/io/perun.clj b/src/io/perun.clj index 295dbfff..cddfdd76 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -196,6 +196,22 @@ (perun/report-debug "gravatar" "found gravatars" (map target-key updated-files)) (perun/set-meta fileset updated-files))))) + +(deftask images + "Assoc list of :images to the post" + [] + (boot/with-pre-wrap fileset + (let [files (perun/get-meta fileset) + images (filter :width files) + groupped-files (group-by :parent-path images) + assoc-images (fn [file] + (if (not? (nil? (:content file))) + (assoc file :images (get groupped-files (:parent-path file))) + file)) + updated-files (map assoc-images files)] + (perun/report-info "images" "add associated images to %s files" (count updated-files)) + (perun/set-meta fileset updated-files)))) + ;; Should be handled by more generic filterer options to other tasks (deftask draft "Exclude draft files" From 86976f6c30870f189b28a4b27f573faf832d9b6e Mon Sep 17 00:00:00 2001 From: Anton Podviaznikov Date: Sat, 16 Jan 2016 00:00:18 -0800 Subject: [PATCH 2/2] add perun/images-exts --- src/io/perun.clj | 7 +++++-- src/io/perun/core.clj | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index cddfdd76..cb284c41 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -91,7 +91,7 @@ pod (create-pod images-resize-deps) files (->> fileset boot/user-files - (boot/by-ext ["png" "jpeg" "jpg"]) + (boot/by-ext perun/images-exts) (map add-filedata)) updated-files (pod/with-call-in @pod (io.perun.contrib.images-resize/images-resize ~(.getPath tmp) ~files ~options))] @@ -202,7 +202,10 @@ [] (boot/with-pre-wrap fileset (let [files (perun/get-meta fileset) - images (filter :width files) + images (filter + (fn [file] + (contains? perun/images-exts (perun/extension file))) + files) groupped-files (group-by :parent-path images) assoc-images (fn [file] (if (not? (nil? (:content file))) diff --git a/src/io/perun/core.clj b/src/io/perun/core.clj index 83666b08..67e14543 100644 --- a/src/io/perun/core.clj +++ b/src/io/perun/core.clj @@ -38,6 +38,8 @@ (defn set-global-meta [fileset data] (vary-meta fileset assoc +global-meta-key+ data)) +(def images-exts #{"jpg" "svg" "png" "gif" "JPG" "SVG" "PNG" "GIF"}) + (defn report-info [task msg & args] (apply u/info (str