summaryrefslogtreecommitdiff
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
parentbc2f34e733a95d697ec301eddfaca55c9f0e1cca (diff)
refactor(build): rewrite build script in Clojure with Babashka
-rw-r--r--build.clj94
-rwxr-xr-xbuild.sh48
2 files changed, 94 insertions, 48 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))
diff --git a/build.sh b/build.sh
deleted file mode 100755
index f5fdface..00000000
--- a/build.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-# to build this site, you must have: git, pnpm, go and hugo
-
-echo "_______ _______ _______ ______ _______ _______ _______ _______ _______ "
-echo "( ____ \( ____ \( ____ \( __ \ ( ____ \( ___ )( ____ )( ____ )( ___ )"
-echo "| ( \/| ( \/| ( \/| ( \ )| ( \/| ( ) || ( )|| ( )|| ( ) |"
-echo "| | | (__ | (__ | | ) || (__ | (___) || (____)|| (____)|| | | |"
-echo "| | ____ | __) | __) | | | || __) | ___ || _____)| __)| | | |"
-echo "| | \_ )| ( | ( | | ) || ( | ( ) || ( | (\ ( | | | |"
-echo "| (___) || (____/\| (____/\| (__/ )| (____/\| ) ( || ) | ) \ \__| (___) |"
-echo "(_______)(_______/(_______/(______/ (_______/|/ \||/ |/ \__/(_______)"
-
-# ========= Pull =========== #
-echo "\n\n1️⃣ Pulling changes from remote.\n"
-git pull
-
-# ======= pre-build ========= #
-echo "\n\n2️⃣ Pre-Build\n"
-pnpm build:uno:prod # build UnoCSS
-
-# check and build Go binaries if needed
-mkdir -p bin
-
-# List of Go programs to build and execute
-go_programs="extract_highlights get_external_link_rank get_internal_link_graph"
-
-for program in $go_programs; do
- if [ ! -f "bin/$program" ]; then
- echo "Building $program..."
- cd scripts && go build -o "../bin/$program" "$program.go" && cd ..
- else
- echo "$program binary already exists in bin/"
- fi
-
- # Execute the binary
- echo "Running $program..."
- "./bin/$program"
-done
-
-# build hugo site
-echo "\n\n3️⃣ Hugo!\n"
-rm -rf ./public # clear old output
-hugo --gc --minify
-
-# post-build
-echo "\n\n4️⃣ Post-Build\n"
-pnpm pagefind --site public # indexing pagefind
-pnpm wm public/index.xml --limit 1 --send # send webmention