Compare commits
No commits in common. "175dae050b53725eb8e1e7dac7de220d69f7a772" and "6ef987639d1e1981ec5ba841b5fe0e6603097d42" have entirely different histories.
175dae050b
...
6ef987639d
|
@ -8,30 +8,29 @@
|
||||||
(def html-dir "./site/html")
|
(def html-dir "./site/html")
|
||||||
(def output-dir "./out")
|
(def output-dir "./out")
|
||||||
|
|
||||||
(defn list-files [directory]
|
|
||||||
(filter #(.isFile %) (file-seq (io/file directory))))
|
|
||||||
|
|
||||||
;; Thank you https://clojure.org/api/cheatsheet
|
;; Thank you https://clojure.org/api/cheatsheet
|
||||||
; Generate a keyword-string map of the templates folder
|
; Generate a keyword-string map of the templates folder
|
||||||
(defn generate-template-map
|
(defn generate-template-map
|
||||||
"Grab all files in the template directory and insert them into a map with
|
"Grab all files in the template directory and insert them into a map with
|
||||||
the filenames as keyword keys"
|
the filenames as keyword keys"
|
||||||
[template-dir]
|
[template-dir]
|
||||||
(let [files (list-files template-dir)]
|
(let [files (filter #(.isFile %) (file-seq (io/file template-dir)))]
|
||||||
(reduce #(assoc %1 (keyword (.getName %2)) (slurp %2)) {} files)))
|
(reduce #(assoc %1 (keyword (.getName %2)) (slurp %2)) {} files)))
|
||||||
|
|
||||||
|
; Generate a string-string map of the new filepaths and the unprocessed contents
|
||||||
(defn generate-output-file-map
|
(defn generate-output-file-map
|
||||||
"Take the input html files, read them, and create a mapping of their paths to
|
"Take the input html files, read them, and create a mapping of their paths to
|
||||||
their contents.
|
their contents.
|
||||||
|
|
||||||
|
This would probably be better as a list of maps each containing a :contents
|
||||||
|
and :path keyword.
|
||||||
"
|
"
|
||||||
[html-dir, output-dir]
|
[html-dir, output-dir]
|
||||||
(let [file-listing (list-files html-dir)
|
(let [file-listing (filter #(.isFile %) (file-seq (io/file html-dir)))
|
||||||
contents (map slurp file-listing)
|
contents (map slurp file-listing)
|
||||||
new-paths (map #(->> %
|
old-paths (map #(.getPath %) file-listing)
|
||||||
.getPath
|
rootless-paths (map #(subs % (count html-dir)) old-paths)
|
||||||
(drop (count html-dir))
|
new-paths (map #(string/join [output-dir %]) rootless-paths)]
|
||||||
(cons output-dir)
|
|
||||||
(string/join)) file-listing)]
|
|
||||||
(zipmap new-paths contents)))
|
(zipmap new-paths contents)))
|
||||||
|
|
||||||
(defn put_file
|
(defn put_file
|
||||||
|
@ -41,6 +40,10 @@ the filenames as keyword keys"
|
||||||
(spit (first file_map_entry) (second file_map_entry)))
|
(spit (first file_map_entry) (second file_map_entry)))
|
||||||
|
|
||||||
(defn insert_templates
|
(defn insert_templates
|
||||||
|
"Go through and check all the template names in the file then
|
||||||
|
mark which templates exist and which dont
|
||||||
|
|
||||||
|
Using this we can report an error for any templates which do not exist"
|
||||||
[file-map-entry template-map]
|
[file-map-entry template-map]
|
||||||
(let [file (first file-map-entry)
|
(let [file (first file-map-entry)
|
||||||
contents (second file-map-entry)
|
contents (second file-map-entry)
|
||||||
|
|
Loading…
Reference in New Issue