#!/usr/bin/env bb ;; Usage: bb build.clj (require '[babashka.tasks :refer [shell]]) (require '[babashka.fs :as fs]) ;; configuration (def go-scripts ["get_external_link_rank" "get_internal_link_graph"]) (def site-src-path "../..") (def site-path "../../public/") (def feed-path (str site-path "index.xml")) (def theme-path "themes/venin/") ;; utilities and macros (defn src-path [s] (str "scripts/" s ".go")) (defn bin-path [s] (str "bin/" s)) (defmacro pnpm [& args] `(shell "pnpm" ~@args)) ;; jobs (defn build-unocss [] (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 {:dir site-src-path} (str theme-path s)))) doall)) (defn index-pagefind-search [] (pnpm "pagefind" "--site" site-path)) (defn send-webmentions [] (pnpm "wm" feed-path "--limit" "1" "--send")) ;; pre and post build (defn pre-build [] (pnpm "install") (build-unocss) (build-go-scripts true) (run-go-scripts)) (defn post-build [] (index-pagefind-search) (send-webmentions)) ;; main (let [[step] *command-line-args*] (case step "pre-build" (pre-build) "post-build" (post-build) (println "Usage: bb build.clj pre-build/post-build")))