move blog logic to own ns

master
Josha von Gizycki 6 years ago
parent cd451f56ac
commit f59cf5641b

@ -0,0 +1,48 @@
(ns equilibrium.blog
(:require [clojure.java.io :as io]
[clojure.string :as string]))
(defn index-file [dir-name root]
(io/file (str root "/blogs/" dir-name "/index.md")))
(defn sites-dir [dir-name root]
(str root "/blogs/" dir-name "/entries"))
(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 config [dir-name analysed-index]
(let [[ix blog-dir-name] (analysed-blog-dir-name 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 target-root [config root]
(str root
"/"
(:blog-dir-name config)))
(comment
(blog-target-root {:blog-dir-name "hudel"})
(blog-sites-dir "datblag"))
(defn write-files [config output-root site-files fill-in-fn]
(let [index-file (io/file (str (target-root config
output-root)
"/index.html"))]
(io/make-parents index-file)
(spit index-file
(fill-in-fn config))))

@ -1,7 +1,8 @@
(ns equilibrium.render (ns equilibrium.render
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.string :as string] [clojure.string :as string]
[markdown.core :as md]) [markdown.core :as md]
[equilibrium.blog :as blog])
(:import java.time.LocalDateTime)) (:import java.time.LocalDateTime))
(def input-root "resources/page") (def input-root "resources/page")
@ -153,54 +154,18 @@
(comment (comment
(blog-dirs)) (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] (defn render-blog [context template dir]
(let [dir-name (filename dir) (let [dir-name (filename dir)
config (merge (blog-config dir-name) index-file (blog/index-file dir-name input-root)
config (merge (blog/config dir-name
(analysed-page index-file))
{:dir dir}) {:dir dir})
target-root (blog-target-root config) blog-sites (md-files (blog/sites-dir dir-name input-root))]
blog-index-file (io/file (str target-root "/index.html")) (blog/write-files config
blog-sites (md-files (blog-sites-dir dir-name))] output-root
(io/make-parents blog-index-file) blog-sites
(spit blog-index-file (partial fill-in-placeholders
(fill-in-placeholders context template config)) context template))
config)) config))
(defn render (defn render

Loading…
Cancel
Save