removed old io
This commit is contained in:
parent
6c1159289d
commit
c6559f8a3e
7 changed files with 86 additions and 81 deletions
|
@ -8,7 +8,6 @@
|
||||||
[selmer.util :refer [set-custom-resource-path!]]
|
[selmer.util :refer [set-custom-resource-path!]]
|
||||||
[text-decoration.core :refer :all]
|
[text-decoration.core :refer :all]
|
||||||
; TODO: remove all cryogen-io occurance
|
; TODO: remove all cryogen-io occurance
|
||||||
[cryogen-core.io :as cryogen-io]
|
|
||||||
[cryogen-core.new-io :as new-io]
|
[cryogen-core.new-io :as new-io]
|
||||||
[cryogen-core.classpath-able-io :as cp-io]
|
[cryogen-core.classpath-able-io :as cp-io]
|
||||||
[cryogen-core.klipse :as klipse]
|
[cryogen-core.klipse :as klipse]
|
||||||
|
@ -227,8 +226,8 @@
|
||||||
"When `clean-urls?` is set, appends `/index.html` before spit; otherwise just spits."
|
"When `clean-urls?` is set, appends `/index.html` before spit; otherwise just spits."
|
||||||
[file-uri {:keys [clean-urls?]} data]
|
[file-uri {:keys [clean-urls?]} data]
|
||||||
(if clean-urls?
|
(if clean-urls?
|
||||||
(cryogen-io/create-file-recursive (new-io/path file-uri "index.html") data)
|
(new-io/create-file-recursive (new-io/path file-uri "index.html") data)
|
||||||
(cryogen-io/create-file file-uri data)))
|
(new-io/create-file file-uri data)))
|
||||||
|
|
||||||
(defn- print-debug-info [data]
|
(defn- print-debug-info [data]
|
||||||
(println "DEBUG:")
|
(println "DEBUG:")
|
||||||
|
@ -263,7 +262,7 @@
|
||||||
:as params} posts]
|
:as params} posts]
|
||||||
(when-not (empty? posts)
|
(when-not (empty? posts)
|
||||||
(println (blue "compiling posts"))
|
(println (blue "compiling posts"))
|
||||||
(cryogen-io/create-folder (new-io/path "/" blog-prefix post-root-uri))
|
(new-io/create-folder (new-io/path "/" blog-prefix post-root-uri))
|
||||||
(doseq [{:keys [uri]
|
(doseq [{:keys [uri]
|
||||||
:as post} posts]
|
:as post} posts]
|
||||||
(println "-->" (cyan uri))
|
(println "-->" (cyan uri))
|
||||||
|
@ -285,7 +284,7 @@
|
||||||
:as params} posts-by-tag]
|
:as params} posts-by-tag]
|
||||||
(when-not (empty? posts-by-tag)
|
(when-not (empty? posts-by-tag)
|
||||||
(println (blue "compiling tags"))
|
(println (blue "compiling tags"))
|
||||||
(cryogen-io/create-folder (new-io/path "/" blog-prefix tag-root-uri))
|
(new-io/create-folder (new-io/path "/" blog-prefix tag-root-uri))
|
||||||
(doseq [[tag posts] posts-by-tag]
|
(doseq [[tag posts] posts-by-tag]
|
||||||
(let [{:keys [name uri]} (tag-info params tag)]
|
(let [{:keys [name uri]} (tag-info params tag)]
|
||||||
(println "-->" (cyan uri))
|
(println "-->" (cyan uri))
|
||||||
|
@ -362,7 +361,7 @@
|
||||||
previews (if (> (count previews) 1)
|
previews (if (> (count previews) 1)
|
||||||
(assoc-in previews [1 :prev] (page-uri "index.html" params))
|
(assoc-in previews [1 :prev] (page-uri "index.html" params))
|
||||||
previews)]
|
previews)]
|
||||||
(cryogen-io/create-folder (new-io/path "/" blog-prefix "p"))
|
(new-io/create-folder (new-io/path "/" blog-prefix "p"))
|
||||||
(doseq [{:keys [index posts prev next]} previews
|
(doseq [{:keys [index posts prev next]} previews
|
||||||
:let [index-page? (= 1 index)]]
|
:let [index-page? (= 1 index)]]
|
||||||
(write-html
|
(write-html
|
||||||
|
@ -418,7 +417,7 @@
|
||||||
[{:keys [blog-prefix author-root-uri author]
|
[{:keys [blog-prefix author-root-uri author]
|
||||||
:as params} posts]
|
:as params} posts]
|
||||||
(println (blue "compiling authors"))
|
(println (blue "compiling authors"))
|
||||||
(cryogen-io/create-folder (new-io/path "/" blog-prefix author-root-uri))
|
(new-io/create-folder (new-io/path "/" blog-prefix author-root-uri))
|
||||||
;; if the post author is empty defaults to config's :author
|
;; if the post author is empty defaults to config's :author
|
||||||
(doseq [{:keys [author posts]} (group-for-author posts author)]
|
(doseq [{:keys [author posts]} (group-for-author posts author)]
|
||||||
(let [uri (page-uri (str author ".html") :author-root-uri params)]
|
(let [uri (page-uri (str author ".html") :author-root-uri params)]
|
||||||
|
@ -454,7 +453,7 @@
|
||||||
:as config}]
|
:as config}]
|
||||||
(let [folders (->> (markup-entries post-root page-root)
|
(let [folders (->> (markup-entries post-root page-root)
|
||||||
(filter template-dir?))]
|
(filter template-dir?))]
|
||||||
(cryogen-io/copy-resources
|
(new-io/copy-resources
|
||||||
(merge config
|
(merge config
|
||||||
{:resources folders
|
{:resources folders
|
||||||
:ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))}))))
|
:ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))}))))
|
||||||
|
@ -464,7 +463,7 @@
|
||||||
[]
|
[]
|
||||||
(try
|
(try
|
||||||
(let [config (-> "templates/config.edn"
|
(let [config (-> "templates/config.edn"
|
||||||
cryogen-io/get-resource
|
new-io/get-resource
|
||||||
slurp
|
slurp
|
||||||
read-string
|
read-string
|
||||||
(update-in [:blog-prefix] (fnil str ""))
|
(update-in [:blog-prefix] (fnil str ""))
|
||||||
|
@ -592,10 +591,10 @@
|
||||||
(compile-authors params posts))
|
(compile-authors params posts))
|
||||||
(println (blue "generating site map"))
|
(println (blue "generating site map"))
|
||||||
(->> (sitemap/generate site-url ignored-files)
|
(->> (sitemap/generate site-url ignored-files)
|
||||||
(cryogen-io/create-file (new-io/path "/" blog-prefix "sitemap.xml")))
|
(new-io/create-file (new-io/path "/" blog-prefix "sitemap.xml")))
|
||||||
(println (blue "generating main rss"))
|
(println (blue "generating main rss"))
|
||||||
(->> (rss/make-channel config posts)
|
(->> (rss/make-channel config posts)
|
||||||
(cryogen-io/create-file (new-io/path "/" blog-prefix rss-name)))
|
(new-io/create-file (new-io/path "/" blog-prefix rss-name)))
|
||||||
(println (blue "generating filtered rss"))
|
(println (blue "generating filtered rss"))
|
||||||
(rss/make-filtered-channels config posts-by-tag)
|
(rss/make-filtered-channels config posts-by-tag)
|
||||||
(println (blue "compiling sass"))
|
(println (blue "compiling sass"))
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
(ns cryogen-core.io
|
|
||||||
(:require [clojure.java.io :as io]
|
|
||||||
[clojure.string :as s]
|
|
||||||
[cryogen-core.new-io :as new-io]
|
|
||||||
[me.raynes.fs :as fs]))
|
|
||||||
|
|
||||||
(def public "resources/public")
|
|
||||||
|
|
||||||
(defn re-filter [bool-fn re & other-res]
|
|
||||||
(let [res (conj other-res re)]
|
|
||||||
(reify java.io.FilenameFilter
|
|
||||||
(accept [this _ name]
|
|
||||||
(bool-fn (some #(re-find % name) res))))))
|
|
||||||
|
|
||||||
(def match-re-filter (partial re-filter some?))
|
|
||||||
(def reject-re-filter (partial re-filter nil?))
|
|
||||||
|
|
||||||
(defn get-resource [resource]
|
|
||||||
(-> resource io/resource io/file))
|
|
||||||
|
|
||||||
(defn ignore [ignored-files]
|
|
||||||
(fn [^java.io.File file]
|
|
||||||
(let [name (.getName file)
|
|
||||||
matches (map #(re-find % name) ignored-files)]
|
|
||||||
(not (some seq matches)))))
|
|
||||||
|
|
||||||
(defn create-folder [folder]
|
|
||||||
(let [loc (io/file (new-io/path public folder))]
|
|
||||||
(when-not (.exists loc)
|
|
||||||
(.mkdirs loc))))
|
|
||||||
|
|
||||||
(defn create-file [file data]
|
|
||||||
(spit (new-io/path public file) data))
|
|
||||||
|
|
||||||
(defn create-file-recursive [file data]
|
|
||||||
(create-folder (.getParent (io/file file)))
|
|
||||||
(create-file file data))
|
|
||||||
|
|
||||||
(defn copy-dir [src target ignored-files]
|
|
||||||
(fs/mkdirs target)
|
|
||||||
(let [^java.io.FilenameFilter filename-filter (apply reject-re-filter ignored-files)
|
|
||||||
files (.listFiles (io/file src) filename-filter)]
|
|
||||||
(doseq [^java.io.File f files]
|
|
||||||
(let [out (io/file target (.getName f))]
|
|
||||||
(if (.isDirectory f)
|
|
||||||
(copy-dir f out ignored-files)
|
|
||||||
(io/copy f out))))))
|
|
||||||
|
|
||||||
(defn copy-resources [{:keys [blog-prefix resources ignored-files]}]
|
|
||||||
(doseq [resource resources]
|
|
||||||
(let [src (str "resources/templates/" resource)
|
|
||||||
target (new-io/path public blog-prefix (fs/base-name resource))]
|
|
||||||
(cond
|
|
||||||
(not (.exists (io/file src)))
|
|
||||||
(throw (IllegalArgumentException. (str "resource " src " not found")))
|
|
||||||
(.isDirectory (io/file src))
|
|
||||||
(copy-dir src target ignored-files)
|
|
||||||
:else
|
|
||||||
(fs/copy src target)))))
|
|
|
@ -9,7 +9,8 @@
|
||||||
(ns cryogen-core.new-io
|
(ns cryogen-core.new-io
|
||||||
(:require [clojure.string :as st]
|
(:require [clojure.string :as st]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[cryogen-core.classpath-able-io :as cp-io]))
|
[cryogen-core.classpath-able-io :as cp-io]
|
||||||
|
[me.raynes.fs :as fs]))
|
||||||
|
|
||||||
(def delete-resources! cp-io/delete-resources!)
|
(def delete-resources! cp-io/delete-resources!)
|
||||||
|
|
||||||
|
@ -77,3 +78,69 @@ if no, return empty vector."
|
||||||
(->> assets
|
(->> assets
|
||||||
filter-file
|
filter-file
|
||||||
filter-ext)))
|
filter-ext)))
|
||||||
|
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; taken from io.clj
|
||||||
|
|
||||||
|
(defn re-filter [bool-fn re & other-res]
|
||||||
|
(let [res (conj other-res re)]
|
||||||
|
(reify java.io.FilenameFilter
|
||||||
|
(accept [this _ name]
|
||||||
|
(bool-fn (some #(re-find % name) res))))))
|
||||||
|
|
||||||
|
(def match-re-filter (partial re-filter some?))
|
||||||
|
(def reject-re-filter (partial re-filter nil?))
|
||||||
|
|
||||||
|
(defn copy-dir [src target ignored-files]
|
||||||
|
(fs/mkdirs target)
|
||||||
|
(let [^java.io.FilenameFilter filename-filter (apply reject-re-filter ignored-files)
|
||||||
|
files (.listFiles (io/file src) filename-filter)]
|
||||||
|
(doseq [^java.io.File f files]
|
||||||
|
(let [out (io/file target (.getName f))]
|
||||||
|
(if (.isDirectory f)
|
||||||
|
(copy-dir f out ignored-files)
|
||||||
|
(io/copy f out))))))
|
||||||
|
|
||||||
|
(defn create-folder [folder]
|
||||||
|
(let [loc (io/file (path public folder))]
|
||||||
|
(when-not (.exists loc)
|
||||||
|
(.mkdirs loc))))
|
||||||
|
|
||||||
|
(defn create-file [file data]
|
||||||
|
(spit (path public file) data))
|
||||||
|
|
||||||
|
(defn create-file-recursive [file data]
|
||||||
|
(create-folder (.getParent (io/file file)))
|
||||||
|
(create-file file data))
|
||||||
|
|
||||||
|
(defn copy-dir [src target ignored-files]
|
||||||
|
(fs/mkdirs target)
|
||||||
|
(let [^java.io.FilenameFilter filename-filter (apply reject-re-filter ignored-files)
|
||||||
|
files (.listFiles (io/file src) filename-filter)]
|
||||||
|
(doseq [^java.io.File f files]
|
||||||
|
(let [out (io/file target (.getName f))]
|
||||||
|
(if (.isDirectory f)
|
||||||
|
(copy-dir f out ignored-files)
|
||||||
|
(io/copy f out))))))
|
||||||
|
|
||||||
|
(defn copy-resources [{:keys [blog-prefix resources ignored-files]}]
|
||||||
|
(doseq [resource resources]
|
||||||
|
(let [src (str "resources/templates/" resource)
|
||||||
|
target (path public blog-prefix (fs/base-name resource))]
|
||||||
|
(cond
|
||||||
|
(not (.exists (io/file src)))
|
||||||
|
(throw (IllegalArgumentException. (str "resource " src " not found")))
|
||||||
|
(.isDirectory (io/file src))
|
||||||
|
(copy-dir src target ignored-files)
|
||||||
|
:else
|
||||||
|
(fs/copy src target)))))
|
||||||
|
|
||||||
|
(defn ignore [ignored-files]
|
||||||
|
(fn [^java.io.File file]
|
||||||
|
(let [name (.getName file)
|
||||||
|
matches (map #(re-find % name) ignored-files)]
|
||||||
|
(not (some seq matches)))))
|
||||||
|
|
||||||
|
(defn get-resource [resource]
|
||||||
|
(-> resource io/resource io/file))
|
|
@ -1,8 +1,7 @@
|
||||||
(ns cryogen-core.rss
|
(ns cryogen-core.rss
|
||||||
(:require [clj-rss.core :as rss]
|
(:require [clj-rss.core :as rss]
|
||||||
[cryogen-core.new-io :as new-io]
|
[cryogen-core.new-io :as new-io]
|
||||||
[text-decoration.core :refer :all]
|
[text-decoration.core :refer :all])
|
||||||
[cryogen-core.io :as cryogen-io])
|
|
||||||
(:import java.util.Date))
|
(:import java.util.Date))
|
||||||
|
|
||||||
(defn posts-to-items [^String site-url posts]
|
(defn posts-to-items [^String site-url posts]
|
||||||
|
@ -33,4 +32,4 @@
|
||||||
(doseq [filter rss-filters]
|
(doseq [filter rss-filters]
|
||||||
(let [uri (new-io/path "/" blog-prefix (str (name filter) ".xml"))]
|
(let [uri (new-io/path "/" blog-prefix (str (name filter) ".xml"))]
|
||||||
(println "\t-->" (cyan uri))
|
(println "\t-->" (cyan uri))
|
||||||
(cryogen-io/create-file uri (make-channel config (get posts-by-tag filter))))))
|
(new-io/create-file uri (make-channel config (get posts-by-tag filter))))))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]
|
||||||
[clojure.java.shell :as shell]
|
[clojure.java.shell :as shell]
|
||||||
[text-decoration.core :refer :all]
|
[text-decoration.core :refer :all]
|
||||||
[cryogen-core.io :as cryogen-io]))
|
[cryogen-core.new-io :as new-io]))
|
||||||
|
|
||||||
(defmacro sh
|
(defmacro sh
|
||||||
[& args]
|
[& args]
|
||||||
|
@ -26,10 +26,10 @@
|
||||||
"Given a Diretory, gets files, Filtered to those having scss or sass
|
"Given a Diretory, gets files, Filtered to those having scss or sass
|
||||||
extention. Ignores files matching any ignored regexps."
|
extention. Ignores files matching any ignored regexps."
|
||||||
[base-dir dir ignored-files]
|
[base-dir dir ignored-files]
|
||||||
(let [^java.io.FilenameFilter filename-filter (cryogen-io/match-re-filter #"(?i:s[ca]ss$)")]
|
(let [^java.io.FilenameFilter filename-filter (new-io/match-re-filter #"(?i:s[ca]ss$)")]
|
||||||
(->> (.listFiles (io/file base-dir dir) filename-filter)
|
(->> (.listFiles (io/file base-dir dir) filename-filter)
|
||||||
(filter #(not (.isDirectory ^java.io.File %)))
|
(filter #(not (.isDirectory ^java.io.File %)))
|
||||||
(filter (cryogen-io/ignore ignored-files))
|
(filter (new-io/ignore ignored-files))
|
||||||
(map #(.getName ^java.io.File %)))))
|
(map #(.getName ^java.io.File %)))))
|
||||||
|
|
||||||
(defn compile-sass-file!
|
(defn compile-sass-file!
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
(ns cryogen-core.sitemap
|
(ns cryogen-core.sitemap
|
||||||
(:require [clojure.xml :refer [emit]]
|
(:require [clojure.xml :refer [emit]]
|
||||||
[cryogen-core.io :as cryogen-io]
|
|
||||||
[cryogen-core.new-io :as new-io])
|
[cryogen-core.new-io :as new-io])
|
||||||
(:import java.util.Date))
|
(:import java.util.Date))
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[hawk.core :as hawk]
|
[hawk.core :as hawk]
|
||||||
[pandect.algo.md5 :as md5]
|
[pandect.algo.md5 :as md5]
|
||||||
[cryogen-core.io :as cryogen-io]))
|
[cryogen-core.new-io :as new-io]))
|
||||||
|
|
||||||
(defn get-assets [path ignored-files]
|
(defn get-assets [path ignored-files]
|
||||||
(->> path
|
(->> path
|
||||||
io/file
|
io/file
|
||||||
file-seq
|
file-seq
|
||||||
(filter #(not (.isDirectory ^java.io.File %)))
|
(filter #(not (.isDirectory ^java.io.File %)))
|
||||||
(filter (cryogen-io/ignore ignored-files))))
|
(filter (new-io/ignore ignored-files))))
|
||||||
|
|
||||||
(defn checksums [path ignored-files]
|
(defn checksums [path ignored-files]
|
||||||
(let [files (get-assets path ignored-files)]
|
(let [files (get-assets path ignored-files)]
|
||||||
|
|
Loading…
Reference in a new issue