diff --git a/src/main/com/grahamcarlyle/blog/build.clj b/src/main/com/grahamcarlyle/blog/build.clj index 016f12f..e2dc246 100644 --- a/src/main/com/grahamcarlyle/blog/build.clj +++ b/src/main/com/grahamcarlyle/blog/build.clj @@ -1,7 +1,7 @@ (ns com.grahamcarlyle.blog.build (:require [babashka.fs :as fs] - [com.grahamcarlyle.blog :as-alias blog] + [com.grahamcarlyle.blog.page :as-alias page] [com.grahamcarlyle.blog.posts :as posts] [clojure.java.io :as io] [clojure.walk :as walk] @@ -9,8 +9,10 @@ (def post-template [:html {:lang "en"} + [:head + [:title ::page/title]] [:body - :blog.page/content]]) + ::page/content]]) (defn substitute [template mapping] (walk/postwalk @@ -20,14 +22,21 @@ x)) template)) +(defn qualify-plain-keyword-keys [mapping ns-str] + (update-keys mapping + #(cond-> % + (and (keyword? %) (nil? (namespace %))) + (->> name (keyword ns-str))))) (defn generate [{:keys [output-dir]}] (fs/delete-tree output-dir) (fs/create-dirs output-dir) - (let [result (posts/parse (slurp (io/file "posts" "first-scrappy.md")))] + (let [result (posts/parse (slurp (io/file "posts" "first-scrappy.md"))) + mapping (merge {::page/content (:hiccup result)} + (qualify-plain-keyword-keys (:meta result) (namespace ::page/placeholder)))] (spit (io/file output-dir "index.html") (h/html (h/raw "") - (substitute post-template {:blog.page/content (:hiccup result)}))))) + (substitute post-template mapping))))) (comment (def output-dir "generated-output") diff --git a/src/test/com/grahamcarlyle/blog/build_test.clj b/src/test/com/grahamcarlyle/blog/build_test.clj index 7e7372b..8b10fd7 100644 --- a/src/test/com/grahamcarlyle/blog/build_test.clj +++ b/src/test/com/grahamcarlyle/blog/build_test.clj @@ -6,4 +6,13 @@ (deftest substitute-test (is (= [:a "hello"] - (build/substitute [:a :foo] {:foo "hello"})))) \ No newline at end of file + (build/substitute [:a :foo] {:foo "hello"})))) + +(deftest qualify-plain-keyword-keys-test + (is (= {:e/a :b + :foo/c :d + "b" "a"} + (build/qualify-plain-keyword-keys {:a :b + :foo/c :d + "b" "a"} + "e")))) \ No newline at end of file