aboutsummaryrefslogtreecommitdiffstats
path: root/src/bitgloo_web/content.clj
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-05-22 09:21:21 -0400
committerClyne Sullivan <clyne@bitgloo.com>2023-05-22 09:21:21 -0400
commitf022f75dad0538ac505111851dc8da7b5aa64e5d (patch)
tree5e998303442e0722d9924d29e10f1b3204981715 /src/bitgloo_web/content.clj
parentcacf5366512f83295d2e2809e4a6a09378f63f42 (diff)
move content code to separate file
Diffstat (limited to 'src/bitgloo_web/content.clj')
-rw-r--r--src/bitgloo_web/content.clj36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/bitgloo_web/content.clj b/src/bitgloo_web/content.clj
new file mode 100644
index 0000000..4aaa2c0
--- /dev/null
+++ b/src/bitgloo_web/content.clj
@@ -0,0 +1,36 @@
+(ns bitgloo-web.content
+ (:gen-class)
+ (:require [clojure.java.io :as io])
+ (:require [clojure.string :as str])
+ (:require [hiccup.page :as page])
+ (:require [markdown.core :refer [md-to-html-string]]))
+
+(def page-header
+ [:div#title-container
+ [:a {:href "/"}
+ [:img#logo {:src "/logo.jpg" :alt "bitgloo logo"}]
+ [:h1 "bitgloo"]]])
+
+(def page-footer [:div#footer [:span "&copy; Clyne Sullivan 2023"]])
+
+(def page-not-found [:div "Page not found"])
+
+(defn md-file? [path] (str/ends-with? path ".md"))
+
+(defn get-file-list [path] (->> path io/file .listFiles sort))
+
+(defn parse-md-file [file] (-> file slurp md-to-html-string))
+
+(defn render-md-files [file-list] (for [f file-list] [:div.block (parse-md-file f)]))
+
+(defn load-page-contents [path]
+ (let [file-list (filter md-file? (get-file-list path))]
+ (if (empty? file-list)
+ page-not-found
+ [:div#posts (render-md-files file-list)])))
+
+(defn load-page [path]
+ (page/html5
+ [:head [:title "bitgloo"] (page/include-css "/main.css")]
+ [:body [:div#container page-header (load-page-contents path) page-footer]]))
+