From 709ca93d984c071c5d067a98269456ec807e4fff Mon Sep 17 00:00:00 2001 From: Archie Hilton Date: Mon, 4 Nov 2024 21:30:13 +0000 Subject: [PATCH] Extract file-listing functionality into list-files --- src/website/core.clj | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/website/core.clj b/src/website/core.clj index ba88e99..45869db 100644 --- a/src/website/core.clj +++ b/src/website/core.clj @@ -8,25 +8,25 @@ (def html-dir "./site/html") (def output-dir "./out") +(defn list-files [directory] + (filter #(.isFile %) (file-seq (io/file directory)))) + ;; Thank you https://clojure.org/api/cheatsheet ; Generate a keyword-string map of the templates folder (defn generate-template-map "Grab all files in the template directory and insert them into a map with the filenames as keyword keys" [template-dir] - (let [files (filter #(.isFile %) (file-seq (io/file template-dir)))] + (let [files (list-files template-dir)] (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 "Take the input html files, read them, and create a mapping of their paths to their contents. - - This would probably be better as a list of maps each containing a :contents - and :path keyword. " [html-dir, output-dir] - (let [file-listing (filter #(.isFile %) (file-seq (io/file html-dir))) + (let [file-listing (list-files html-dir) contents (map slurp file-listing) old-paths (map #(.getPath %) file-listing) rootless-paths (map #(subs % (count html-dir)) old-paths) @@ -40,10 +40,6 @@ the filenames as keyword keys" (spit (first file_map_entry) (second file_map_entry))) (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] (let [file (first file-map-entry) contents (second file-map-entry)