summaryrefslogtreecommitdiff
path: root/build.clj
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-04-02 11:48:46 +0800
committereltrac <hi@eltr.ac>2026-04-02 11:48:46 +0800
commitb0984fe2fb048cfc6e3ba97782bc8a038783a88f (patch)
tree5c445736ea6b871f7d2c8289b517d6539355884e /build.clj
parentbc2f34e733a95d697ec301eddfaca55c9f0e1cca (diff)
refactor(build): rewrite build script in Clojure with Babashka
Diffstat (limited to 'build.clj')
-rw-r--r--build.clj94
1 files changed, 94 insertions, 0 deletions
diff --git a/build.clj b/build.clj
new file mode 100644
index 00000000..330caa28
--- /dev/null
+++ b/build.clj
@@ -0,0 +1,94 @@
+#!/usr/bin/env bb
+;; Usage: bb build.clj <no_chache?> <rebuild_scripts?>
+
+(require '[babashka.tasks :refer [shell]])
+(require '[babashka.fs :as fs])
+
+;; configuration
+
+(def go-scripts ["extract_highlights"
+ "get_external_link_rank"
+ "get_internal_link_graph"])
+(def site-path "public/")
+(def feed-path (str site-path "index.xml"))
+
+;; utilities
+
+(defn src-path [s]
+ (str "scripts/" s ".go"))
+(defn bin-path [s]
+ (str "bin/" s))
+
+(defn pnpm [& args]
+ (apply shell "pnpm" args))
+
+;; banner
+
+(defn banner []
+ (println "
+ ▐
+ ▄▄ ▄▖ ▄▖ ▄▟ ▄▖ ▄▖ ▗▄▖ ▖▄ ▄▖
+▐▘▜ ▐▘▐ ▐▘▐ ▐▘▜ ▐▘▐ ▝ ▐ ▐▘▜ ▛ ▘▐▘▜
+▐ ▐ ▐▀▀ ▐▀▀ ▐ ▐ ▐▀▀ ▗▀▜ ▐ ▐ ▌ ▐ ▐
+▝▙▜ ▝▙▞ ▝▙▞ ▝▙█ ▝▙▞ ▝▄▜ ▐ ▐▙▛ ▌ ▝▙▛
+ ▖▐ ▐
+ ▝▘ ▝
+ "))
+
+;; build steps
+
+(defn pull-new-changes []
+ (shell "git" "pull"))
+
+(defn build-unocss []
+ (shell "pnpm" "build:uno:prod"))
+
+(defn build-go-scripts [on-demand]
+ (when-not (fs/exists? "bin")
+ (fs/create-dir "bin"))
+ (cond->> go-scripts
+ true (filter #(fs/exists? (src-path %)))
+ on-demand (remove #(fs/exists? (bin-path %)))
+ true (map (fn [s]
+ (println "Building script" s)
+ (shell "go" "build" "-o"
+ (bin-path s)
+ (src-path s))))
+ true doall))
+
+(defn run-go-scripts []
+ (->> go-scripts
+ (map bin-path)
+ (filter fs/exists?)
+ (map (fn [s]
+ (println "Running script" s)
+ (shell s)))
+ doall))
+
+(defn build-site [no-cache?]
+ (shell "hugo" "--gc" "--minify"
+ (cond no-cache? "--ignoreCache")))
+
+(defn index-pagefind-search []
+ (pnpm "pagefind" "--site" site-path))
+
+(defn send-webmentions []
+ (pnpm "wm" feed-path "--limit" "1" "--send"))
+
+;; main process
+
+(defn before-build-site [rebuild-scripts?]
+ (pull-new-changes)
+ (build-unocss)
+ (build-go-scripts (not (parse-boolean (or rebuild-scripts? "false"))))
+ (run-go-scripts))
+
+(defn after-build-site []
+ (index-pagefind-search)
+ (send-webmentions))
+
+(let [[no-cache? rebuild-scripts?] *command-line-args*]
+ (banner)
+ (before-build-site rebuild-scripts?)
+ (build-site (parse-boolean (or no-cache? "false")))
+ (after-build-site))