blob: 4aaa2c069f3dc866da506a6732a5b329a1680c2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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]]))
|