Cleanup
This commit is contained in:
parent
749eb7bb53
commit
f83497b152
1 changed files with 9 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
|||
(ns cryogen-core.io
|
||||
(:require [clojure.java.io :refer [file]]
|
||||
[me.raynes.fs :as fs]
|
||||
[clojure.java.io :as io]))
|
||||
(:require [clojure.java.io :as io]
|
||||
[me.raynes.fs :as fs]))
|
||||
|
||||
(def public "resources/public")
|
||||
|
||||
|
@ -10,7 +9,7 @@
|
|||
(.getContextClassLoader)
|
||||
(.getResource resource)
|
||||
(.toURI)
|
||||
(file)))
|
||||
(io/file)))
|
||||
|
||||
(defn find-assets [f ext]
|
||||
(->> (get-resource f)
|
||||
|
@ -18,28 +17,27 @@
|
|||
(filter (fn [file] (-> file .getName (.endsWith ext))))))
|
||||
|
||||
(defn create-folder [folder]
|
||||
(let [loc (file (str public folder))]
|
||||
(let [loc (io/file (str public folder))]
|
||||
(when-not (.exists loc)
|
||||
(.mkdirs loc))))
|
||||
|
||||
(defn wipe-public-folder [keep-files]
|
||||
(let [filenamefilter (reify java.io.FilenameFilter (accept [this _ filename] (not (some #{filename} keep-files))))]
|
||||
(doseq [path (.listFiles (file public) filenamefilter)]
|
||||
(doseq [path (.listFiles (io/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))))))
|
||||
(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-resources [{:keys [blog-prefix resources]}]
|
||||
(doseq [resource resources]
|
||||
(let [src (str "resources/templates/" resource)
|
||||
target (str public blog-prefix "/" resource)]
|
||||
(cond
|
||||
(not (.exists (file src)))
|
||||
(not (.exists (io/file src)))
|
||||
(throw (IllegalArgumentException. (str "resource " src " not found")))
|
||||
(.isDirectory (file src))
|
||||
(.isDirectory (io/file src))
|
||||
(fs/copy-dir src target)
|
||||
:else
|
||||
(fs/copy src target)))))
|
||||
|
|
Loading…
Reference in a new issue