some code refactoring

master
Josha von Gizycki 6 years ago
parent fa260d148c
commit bf98817cf1

@ -70,3 +70,28 @@
:let [target (site->target-file config output-root site)]]
(spit target
(fill-in-fn site))))
(defn sites-preview [sites]
(reduce (fn [res site]
(let [content (:content site)
divider-pos (string/index-of content "<p><blink></p>")
length (count content)
end (or divider-pos length)
pre-content (subs content 0 end)
article-link (str "<a href=\""
(:link site)
"\">"
"↪"
(when divider-pos "…")
"</a>")]
(str res
"<article>"
pre-content
"<p class=\"article-link\">"
article-link
"</p>"
"</article>")))
""
(take-last
5
(reverse sites))))

@ -11,3 +11,10 @@
.toPath
.getFileName
.toString))
(defn env-val [env-name]
(let [env-val (System/getenv env-name)]
(when (= nil env-val)
(throw (ex-info (str "env var not found " env-name)
{:env-var env-name})))
env-val))

@ -25,22 +25,6 @@
(defn index-template []
(slurp (str input-root "/index.html")))
(comment
(defn navcode [sites]
(let [sorted-sites (sort-by #(core/filename %) sites)
clean-file-name-fn #(core/clean-name (core/filename %))
nav-line-fn #(str "<li>"
"<a href=\""
(clean-file-name-fn %)
".html\">"
(clean-file-name-fn %)
"</a></li>")]
(str "<ol>"
(reduce #(str %1 (nav-line-fn %2))
""
sorted-sites)
"</ol>"))))
(defn site-destination [filename]
(str output-root
"/"
@ -129,36 +113,8 @@
(comment
(particle-content "aside"))
(defn blog-sites-preview [blog-name]
(reduce (fn [res site]
(let [content (:content site)
divider-pos (string/index-of content "<p><blink></p>")
length (count content)
end (or divider-pos length)
pre-content (subs content 0 end)
article-link (str "<a href=\""
(:link site)
"\">"
"↪"
(when divider-pos
"…")
"</a>")]
(str res
"<article>"
pre-content
"<p class=\"article-link\">"
article-link
"</p>"
"</article>")))
""
(->> blog-name
blog-sites
(take-last 5)
reverse)))
(defn fill-in-placeholders [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 #"&:generated-at" (now-str)))
@ -171,18 +127,14 @@
(first particle)
(particle-content (second particle))))
blog-sites-fn (fn [result [match-str blog-name]]
(string/replace
result
(let [sites (blog-sites blog-name)]
(string/replace result
match-str
(blog-sites-preview blog-name)))
(blog/sites-preview sites))))
envs-fn (fn [result [match-str env-name]]
(when (= nil (System/getenv env-name))
(throw (ex-info (str "env var not found " env-name)
{:env-var env-name
:match-str match-str})))
(string/replace result
match-str
(System/getenv env-name)))]
(core/env-val env-name)))]
(as-> simple $
(reduce particle-fn $ particles)
(reduce blog-sites-fn $ last-blog-sites)

Loading…
Cancel
Save