massi-world

this website of mine
Log | Files | Refs

commit 34b3890eb0356aac3aeb38f63b45c6241399b15d
parent 9928b8a4878b4e1b27e6ce0b44dfda199d577246
Author: massi <mdsiboldi@gmail.com>
Date:   Thu,  1 Aug 2024 15:22:33 -0700

build niceties and organization. replace md generator.

Diffstat:
MMakefile | 13++++---------
MREADME.org | 13++++++++-----
Abin/marked-custom.js | 8++++++++
Mdeps.edn | 4+---
Apackage-lock.json | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackage.json | 14++++++++++++++
Msrc/core.clj | 43++++++++++++++++++++++++++++++-------------
Msrc/site.clj | 52++++++++++++++++++++++++++--------------------------
Msrc/swatchbuckler.clj | 43++++++++++++++++++++++++++++++-------------
9 files changed, 187 insertions(+), 69 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,8 +1,3 @@ -ifeq ($(MW_ENV), dev) - SITE_ROOT := /massi.world - SB_ROOT := /swatchbuckler.massi.world -endif - clean: rm -r build @@ -12,21 +7,21 @@ build: mkdir -p build/massi.world cp -r site/static/* build/massi.world cd build/massi.world && ln -s ../shared/* . - WEB_ROOT=$(SITE_ROOT) clj -X site/build + clj -X site/build mkdir -p build/swatchbuckler.massi.world/js cp -r shared/static/* build/swatchbuckler.massi.world cp swatchbuckler/node_modules/d3-color/dist/d3-color.min.js build/swatchbuckler.massi.world/js - WEB_ROOT=$(SB_ROOT) clj -X swatchbuckler/build + clj -X swatchbuckler/build serve: make clean MW_ENV=dev make build - http-server build -p 8080 -S -C cert.pem & while true; do \ + http-server build -p 8080 & while true; do \ inotifywait @./build -qre close_write .; \ make clean; \ MW_ENV=dev make build; \ done publish: build - rsync -rl --delete build/ "${MASSIWORLD_HOST}:/home/protected/builds/massi-world" + rsync -rl --delete build/ "mw:/home/protected/builds/massi-world" diff --git a/README.org b/README.org @@ -4,6 +4,10 @@ site generator in clojure from the ground up becuse it's interesting and I've been meaning to use a lisp more. clojure is pretty cool so far. +* Dependencies 🔗 +- marked - md generation +- prettier - formatting html output for debugging purposes + * Tips ‼ ** SSL on dev Run this in project root for ssl on dev server (so we can keep @@ -18,6 +22,10 @@ https://www.npmjs.com/package/http-server seems like it has some advice. ** Publishing +- Running make build will build using the prod env +- Make serve will build using the dev env +- To make a one-off dev build, run =MW_ENV=dev make build= + Edit =~/.ssh/config= like so the Makefile and your computer are in agreement about where to push. #+BEGIN_SRC @@ -26,11 +34,6 @@ Host mw User xxx #+END_SRC -* Notes ✍ -- Running make build will build using the prod env -- Make serve will build using dev -- To make a one-off dev build, run =MW_ENV=dev make build= - * Todo 😴 - Split out js in swatchbuckler - Finish the website diff --git a/bin/marked-custom.js b/bin/marked-custom.js @@ -0,0 +1,8 @@ +#!/usr/bin/node + +import { marked } from "marked"; +import { gfmHeadingId } from "marked-gfm-heading-id"; + +marked.use(gfmHeadingId({addAnchor: true})); + +import 'marked/bin/marked'; diff --git a/deps.edn b/deps.edn @@ -1,3 +1 @@ -{:deps { - hiccup/hiccup {:mvn/version "2.0.0-RC3"} - markdown-clj/markdown-clj {:mvn/version "1.12.1"}}} +{:deps {hiccup/hiccup {:mvn/version "2.0.0-RC3"}}} diff --git a/package-lock.json b/package-lock.json @@ -0,0 +1,66 @@ +{ + "name": "massi-world", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "massi-world", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "marked": "^13.0.3", + "marked-gfm-heading-id": "github:mdsib/marked-gfm-heading-id", + "prettier": "^3.3.3" + } + }, + "node_modules/github-slugger": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-2.0.0.tgz", + "integrity": "sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw==", + "dev": true, + "license": "ISC" + }, + "node_modules/marked": { + "version": "13.0.3", + "resolved": "https://registry.npmjs.org/marked/-/marked-13.0.3.tgz", + "integrity": "sha512-rqRix3/TWzE9rIoFGIn8JmsVfhiuC8VIQ8IdX5TfzmeBucdY05/0UlzKaw0eVtpcN/OdVFpBk7CjKGo9iHJ/zA==", + "dev": true, + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/marked-gfm-heading-id": { + "version": "4.0.0", + "resolved": "git+ssh://git@github.com/mdsib/marked-gfm-heading-id.git#92e4eb14e3329b7248cdb94fea39a3d49b6d17eb", + "dev": true, + "license": "MIT", + "dependencies": { + "github-slugger": "^2.0.0" + }, + "peerDependencies": { + "marked": ">=13 <14" + } + }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json @@ -0,0 +1,14 @@ +{ + "name": "massi-world", + "version": "1.0.0", + "type": "module", + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "devDependencies": { + "marked": "^13.0.3", + "marked-gfm-heading-id": "github:mdsib/marked-gfm-heading-id", + "prettier": "^3.3.3" + } +} diff --git a/src/core.clj b/src/core.clj @@ -1,8 +1,16 @@ (ns core (:require [hiccup2.core :as h] [clojure.java.io :as io] - [markdown.core :as md] - [clojure.string :as cstr])) + [clojure.string :as cstr] + [clojure.java.shell :as shell])) + +(defn prnt [level emoji & words] + (println (apply str + (apply str (repeat level "\t")) + " " + emoji + "\t" + words))) (def WEB_ROOT (or (System/getenv "WEB_ROOT") "")) @@ -30,8 +38,7 @@ (->> pg-key-or-spec getspec :path - (into [domain]) - (into (if is-dev ["localhost:8080"] [])) + (into (if is-dev ["localhost:8080" domain] [domain])) without-index (cstr/join "/")))) (url @@ -91,8 +98,8 @@ document.documentElement.classList.add('js');")] ;; todo figure out how to thread project-specific p stuff into this. (defn massi-world-domain-stuff [url p {:or {img {:src "https://massi.world/shared-assets/icon-180-180.png" - :desc "an undiscovered planet."}} - :as argmap}] + :desc "an undiscovered planet."}} + :as argmap}] (concat (base-head-stuff url argmap) (list [:link {:rel "shortcut icon" :href (p "/favicon.ico")}] [:link {:rel "icon" :type "image/png" :sizes "16x16" :href (p "/shared-assets/icon-16-16.png")}] @@ -117,21 +124,31 @@ document.documentElement.classList.add('js');")] (defn process-templ [in-file out-file hole-map] (if (or (not (string? in-file)) - (not (string? out-file)) (= in-file out-file)) (throw (Exception. "unable to process template. either in/out files not specified or they're the same. which would be weird."))) - (spit out-file (fill-templ (slurp in-file) hole-map))) + (let [out-str (fill-templ (slurp in-file) hole-map)] + (if out-file + (spit out-file out-str) + out-str))) (defn md-hole [hole-map] (fn [text state] [(fill-templ text hole-map) state])) +(defn md-to-html [in-str] + (:out (shell/sh "bin/marked-custom.js" :in in-str))) + (defn md ([file] (md file nil)) ([file hole-fillers] - (let* [base-args [:heading-anchors true] - args (if (map? hole-fillers) - (into base-args [:custom-transformers [(md-hole hole-fillers)]]) - base-args)] - (h/raw (apply md/md-to-html-string (slurp file) args))))) + (let [templ-str (slurp file) + md-str (fill-templ templ-str hole-fillers) + html-str (md-to-html md-str)] + (h/raw html-str)))) +(defn prettify-html [html-str] + (:out (shell/sh + "prettier" + "--stdin-filepath" + "foo.html" ; just need to end in .html so prettier knows what to do. + :in html-str))) diff --git a/src/site.clj b/src/site.clj @@ -1,7 +1,6 @@ (ns site (:require [hiccup2.core :as h] [clojure.java.io :as io] - [markdown.core :as md] [clojure.string :as cstr] [core])) @@ -51,8 +50,7 @@ [:html.no-js [:head (site-header - (merge (getspec pg-key-or-spec) - {:path (p-url pg-key-or-spec)}))]] + (getspec pg-key-or-spec))]] [:body (seq body)])) (defmacro defpage [key spec & render] @@ -72,34 +70,34 @@ (.format (java.text.SimpleDateFormat. "MM/dd/yyyy hh:mm:ssa z") (new java.util.Date))]) -(defn mk-page [{:keys [path fn]}] - (let* [out-dir "build/massi.world" - out-file (str out-dir path) - out-str (str (apply fn `(~path)))] - (io/make-parents out-file) - (spit out-file out-str) - (println "wrote" out-file) - out-str)) - (defn build-manifest [] + (core/prnt 1 "🤖" "writing build/massi.world/manifest.json") (core/process-templ "site/manifest.templ.json" "build/massi.world/manifest.json" {:icon-192 (p "/shared-assets/icon-192-192.png") - :index-url (p-url :home)}) - (println "wrote manifest.")) + :index-url (p-url :home)})) (defn build-css [] + (core/prnt 1 "🖼" "writing build/massi.world/style.css") (core/process-templ "site/style.templ.css" "build/massi.world/style.css" - {:web-root core/WEB_ROOT}) - (println "wrote style.css")) + {:web-root core/WEB_ROOT})) (defn render-page [pgkey] - (let* [out-file (p-out pgkey) - out-str (str ((-> pgkey getspec :render)))] + (core/prnt 1 "👉" pgkey) + (let [out-file (p-out pgkey) + out-str (do (core/prnt 2 "🌀" "rendering " pgkey) + (str ((-> pgkey getspec :render)))) + out-str (if (cstr/ends-with? out-file ".html") + (do + (core/prnt 2 "✨" (str "tidying html...")) + (core/prettify-html out-str)) + out-str)] + (io/make-parents out-file) + (core/prnt 2 "✍" "writing " out-file) (spit out-file out-str) - (println "wrote" out-file))) + (core/prnt 2 "✅" "done!"))) (defpage :home {:path ["index.html"] :title "massi world" @@ -132,11 +130,13 @@ ;; _ arg is so we can call this with clj -X massi-world/build ;; _ is expected to be a map, and clojure complains if we don't accept it (defn build [_] - (println "building site...") - (build-manifest) - (build-css) + (println) + (core/prnt 0 "🌎" domain) (time - (doseq [pgkey (keys pages)] - (render-page pgkey)))) - -(build nil) + (do + (doseq [pgkey (keys pages)] + (render-page pgkey)) + (build-manifest) + (build-css) + (print "\t 🕜\t"))) + (println)) diff --git a/src/swatchbuckler.clj b/src/swatchbuckler.clj @@ -9,17 +9,34 @@ :desc "generate fg/bg pairs from a midtone"}) (defn build [_] - (core/process-templ - "swatchbuckler/index.templ.html" - "build/swatchbuckler.massi.world/index.html" - {:head-content (core/massi-world-domain-stuff - (p-url spec) - p - spec)}) - (println "wrote build/swatchbuckler.massi.world/index.html") + (println) + (core/prnt 0 "🌎" domain) + (time + (do + (let [templ-file "swatchbuckler/index.templ.html" + out-file "build/swatchbuckler.massi.world/index.html" + html-str (do + (core/prnt 1 "👉" templ-file) + (core/prnt 2 "🌀" "rendering " templ-file) + (core/fill-templ + (slurp templ-file) + {:head-content (core/massi-world-domain-stuff + (p-url spec) + p + spec)})) + html-str (do + (core/prnt 2 "✨" (str "tidying html...")) + (core/prettify-html html-str))] + + (core/prnt 2 "✍" "writing " out-file) + (spit out-file html-str) + (core/prnt 2 "✅" "done!")) - (core/process-templ - "swatchbuckler/manifest.templ.json" - "build/swatchbuckler.massi.world/manifest.json" - {:icon-192 (p "/shared-assets/icon-192-192.png") - :index-url (p-url spec)})) + (core/process-templ + "swatchbuckler/manifest.templ.json" + "build/swatchbuckler.massi.world/manifest.json" + {:icon-192 (p "/shared-assets/icon-192-192.png") + :index-url (p-url spec)}) + (core/prnt 1 "🤖" "wrote build/massi.world/manifest.json") + (print "\t 🕜\t"))) + (println))