massi_world.clj (2930B)
1 (ns massi-world 2 (:require [hiccup2.core :as h] 3 [clojure.java.io :as io] 4 [markdown.core :as md] 5 [clojure.string :as cstr] 6 [share :as shr])) 7 8 (defn massi-world-site-stuff [argmap] 9 (concat (shr/massi-world-domain-stuff argmap) 10 (list [:link {:rel "stylesheet" :href "/static/style.css"}] 11 [:link {:rel "manifest" :href "/manifest.json"}]))) 12 13 14 (defn with-page [argmap & body] 15 (h/html (h/raw "<!DOCTYPE html>") 16 [:html.no-js 17 [:head 18 (massi-world-site-stuff 19 (merge argmap 20 {:path (str "https://massi.world" (get argmap :path))}))]] 21 [:body (seq body)])) 22 23 (defn header [] 24 [:header "massi world 🦝"]) 25 (defn footer [] 26 [:footer 27 "Last generated: " 28 (.format (java.text.SimpleDateFormat. "MM/dd/yyyy hh:mm:ssa z") 29 (new java.util.Date))]) 30 31 (defn mk-home [path] 32 (with-page {:path path 33 :title "massi world" 34 :desc "home"} 35 (header) 36 [:section 37 [:h1 "projects"] 38 [:ul 39 [:li [:a {:href "/projects/color-synth.html"} "color-synth"]]] 40 (footer)])) 41 42 (defn mk-page [{:keys [path fn]}] 43 (let* [out-dir "build" 44 out-file (str out-dir path) 45 out-str (str (apply fn `(~path)))] 46 (io/make-parents out-file) 47 (spit out-file out-str) 48 (println "wrote" out-file) 49 out-str)) 50 51 52 ;; _ arg is so we can call this with clj -X massi-world/build 53 ;; _ is expected to be a map, and clojure complains if we don't accept it 54 (defn build [_] 55 (println "building site...") 56 (time 57 (doseq [spec [{:path "/index.html" :fn mk-home} 58 {:path "/projects/color-synth.html" 59 :fn #(with-page {:path % 60 :title "projects -> color-synth" 61 :desc "a digital video synthesizer on the web"} 62 (header) 63 [:main.color-synth 64 [:div.md (shr/md "src/color-synth.md" 65 {:samples [:div.samples 66 [:img {:src "/static/color-synth-sample-1.webp" 67 :alt "a pixelated wobbling smiley face"}] 68 [:img {:src "/static/color-synth-sample-2.webp" 69 :alt "jagged vibrant waves"}] 70 [:img {:src "/static/color-synth-sample-3.webp" 71 :alt "a complicated animation. fuzzy, sharp, and checkered"}] 72 [:img {:src "/static/color-synth-sample-4.webp" 73 :alt "mellow swampy waves"}]]})]] 74 (footer))}]] 75 (mk-page spec)))) 76 77 (build nil)