move content code to separate file
parent
cacf536651
commit
f022f75dad
@ -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 "© 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]]))
|
||||||
|
|
Loading…
Reference in New Issue