summaryrefslogtreecommitdiff
path: root/build.clj
blob: 62b81497608ea5062e8973cc5a49d531dc45ba8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/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")))