first shot at blogs

master
Josha von Gizycki 6 years ago
parent 093bd816e5
commit 89c6377a9b

@ -0,0 +1,4 @@
---
{:title "datblag"}
---

@ -5,6 +5,7 @@
(:import java.time.LocalDateTime))
(def input-root "resources/page")
(def output-root "target/page")
(defn filename [file]
(-> file
@ -48,7 +49,8 @@
"</ol>")))
(defn site-destination [filename]
(str "target/page/"
(str output-root
"/"
(clean-name filename)
".html"))
@ -99,9 +101,9 @@
(defn fill-in-placeholders [context html page]
(let [simple (-> html
(string/replace #"&:nav" (:navcode context))
(string/replace #"&:content" (:content page))
(string/replace #"&:title" (get-in page [:metadata :title]))
(string/replace #"&:nav" (:navcode context ""))
(string/replace #"&:content" (:content page ""))
(string/replace #"&:title" (get-in page [:metadata :title] ""))
(string/replace #"&:generated-at" (now-str)))
particles (particles-in-content simple)]
(reduce (fn [result particle]
@ -141,16 +143,78 @@
(clear-dir file))
(.delete file))))
(defn blog-dirs []
(->> (str input-root "/blogs")
io/file
.listFiles
(filter #(.isDirectory %))
(sort-by #(filename %))))
(comment
(blog-dirs))
(defn blog-index-file [dir-name]
(io/file (str input-root "/blogs/" dir-name "/index.md")))
(defn analysed-blog-dir-name [dir-name]
(let [name-parts (string/split dir-name #"\+")]
(case (count name-parts)
1 ["" (first name-parts)]
2 [(first name-parts) (second name-parts)])))
(comment
(analysed-blog-dir-name "hudel")
(analysed-blog-dir-name "4711+wudel"))
(defn blog-config [dir-name]
(let [[ix blog-dir-name] (analysed-blog-dir-name dir-name)
analysed-index (analysed-page (blog-index-file dir-name))]
(merge {:ix ix
:blog-dir-name blog-dir-name}
(update-in analysed-index
[:metadata :page-size]
#(or % 10)))))
(comment
(blog-index-file "datblag")
(blog-config "datblag"))
(defn blog-target-root [config]
(str output-root
"/"
(:blog-dir-name config)))
(defn blog-sites-dir [dir-name]
(str input-root "/blogs/" dir-name "/entries"))
(comment
(blog-target-root {:blog-dir-name "hudel"})
(blog-sites-dir "datblag"))
(defn render-blog [context template dir]
(let [dir-name (filename dir)
config (merge (blog-config dir-name)
{:dir dir})
target-root (blog-target-root config)
blog-index-file (io/file (str target-root "/index.html"))
blog-sites (md-files (blog-sites-dir dir-name))]
(io/make-parents blog-index-file)
(spit blog-index-file
(fill-in-placeholders context template config))
config))
(defn render
"Renders all markdown pages under resources/user using the structure in resources/user/structure to target/page"
[project]
(clear-dir (io/file "target/page"))
(.mkdirs (io/file "target/page"))
(clear-dir (io/file output-root))
(io/make-parents output-root)
(let [sites (md-files (str input-root "/sites"))
rendered-sites (map analysed-page sites)
template (index-template)
context {:navcode (navcode sites)}]
(write-sites context template rendered-sites)))
(write-sites context template rendered-sites)
(for [blog-dir (blog-dirs)]
(render-blog context template blog-dir))))
(comment
(render {})

Loading…
Cancel
Save