change replacement syntax to &:

master
Josha von Gizycki 6 years ago
parent fba3fd8577
commit 093bd816e5

@ -1,17 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Equilibrium page &title</title> <meta charset="UTF-8">
<!-- generated at &:generated-at -->
<title>Equilibrium page &:title</title>
</head> </head>
<body> <body>
<nav> <nav>
&nav &:nav
</nav> </nav>
<main> <main>
&content &:content
</main> </main>
<aside> <aside>
&particle:aside &:particle:aside
</aside> </aside>
</body> </body>
</html> </html>

@ -89,7 +89,7 @@
(page-content "aiaiaiai")) (page-content "aiaiaiai"))
(defn particles-in-content [content] (defn particles-in-content [content]
(re-seq #"&particle:([^\s]+)" content)) (re-seq #"&:particle:([^\s]+)" content))
(comment (comment
(particles-in-content "asd &particle:hullu")) (particles-in-content "asd &particle:hullu"))
@ -99,10 +99,10 @@
(defn fill-in-placeholders [context html page] (defn fill-in-placeholders [context html page]
(let [simple (-> html (let [simple (-> html
(string/replace #"&nav" (:navcode context)) (string/replace #"&:nav" (:navcode context))
(string/replace #"&content" (:content page)) (string/replace #"&:content" (:content page))
(string/replace #"&title" (get-in page [:metadata :title])) (string/replace #"&:title" (get-in page [:metadata :title]))
(string/replace #"&generated-at" (now-str))) (string/replace #"&:generated-at" (now-str)))
particles (particles-in-content simple)] particles (particles-in-content simple)]
(reduce (fn [result particle] (reduce (fn [result particle]
(string/replace result (string/replace result
@ -113,10 +113,10 @@
(comment (comment
(fill-in-placeholders {:navcode "hhh"} (fill-in-placeholders {:navcode "hhh"}
"&nav &content &particle:aside\n " "&:nav &content &:particle:aside\n "
{:content "dinge"}) {:content "dinge"})
(fill-in-placeholders {:navcode "hhh"} (fill-in-placeholders {:navcode "hhh"}
"&nav &content &particle:aside\n &generated-at" "&:nav &:content &:particle:aside\n &:generated-at"
{:content "dinge"}) {:content "dinge"})
) )
@ -133,9 +133,18 @@
:content (-> content page-content render-markdown) :content (-> content page-content render-markdown)
:metadata (page-metadata content)})) :metadata (page-metadata content)}))
(defn clear-dir [dir]
(doseq [file (file-seq dir)]
(when (.exists dir)
(when (and (.isDirectory file)
(not= dir file))
(clear-dir file))
(.delete file))))
(defn render (defn render
"Renders all markdown pages under resources/user using the structure in resources/user/structure to target/page" "Renders all markdown pages under resources/user using the structure in resources/user/structure to target/page"
[project] [project]
(clear-dir (io/file "target/page"))
(.mkdirs (io/file "target/page")) (.mkdirs (io/file "target/page"))
(let [sites (md-files (str input-root "/sites")) (let [sites (md-files (str input-root "/sites"))
rendered-sites (map analysed-page sites) rendered-sites (map analysed-page sites)

Loading…
Cancel
Save