~subsetpark/bagatto-website

ref: e31ca7a88451bc78572c6a5a86b53f74c276b1bc bagatto-website/web.janet -rw-r--r-- 2.9 KiB
e31ca7a8 — Zach Smith complete-build? 2 months ago
                                                                                
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
(bagatto/set-defaults! {:attrs bagatto/parse-mago})
(bagatto/set-output-dir! "site")

(def index-path "index.html")
(def guides-path "guides.html")
(def api-path "api.html")
(def manual-path "manual.html")
(def getting-path "getting.html")
(def logo-path "images/logo.svg")

(def guide-path (bagatto/%p "guides" '%i :title '% ".html"))
(def build-path (bagatto/path-copier "builds"))

(defn parse-build
  [_src {:path path}]
  (let [attrs @{:path path}
        [size] (->> (sh/$< ls -sh ,path) (string/split " "))
        [sha] (->> (sh/$< sha256sum ,path) (string/split " "))]
    (put attrs :filename (path/basename path))
    (put attrs :size size)
    (put attrs :sha sha)))

(def data {:config {:attrs {:title "Bagatto"
                            :subtitle "A transparent, extensible static site generator"
                            :repo "https://sr.ht/~subsetpark/bagatto/"
                            :description "Bagatto: a transparent, extensible static site generator" }}
           :static {:src (bagatto/* "static/*.png")
                    :attrs bagatto/parse-base}
           :css {:src (bagatto/slurp-* "static/*.css")
                 :attrs bagatto/parse-base}
           :api {:src "../bagatto/api.md"}
           :manual {:src "../bagatto/MANUAL.md"}
           :logo {:src "../bagatto/assets/logo-trans.svg"}
           :blurbs {:src (bagatto/slurp-* "blurbs/*")
                    :transform (bagatto/attr-sorter :idx)}
           :guides {:src (bagatto/slurp-* "guides/*")
                    :transform (bagatto/attr-sorter :idx)}
           :getting {:src "getting.md"}
           :builds {:src (bagatto/* "builds/*")
                    :attrs parse-build
                   :transform reverse}})

(defn htmlmin [html]
  (sh/$< echo ,(string html) | htmlmin))

(defn renderer [template &opt args]
  (comp htmlmin (bagatto/renderer template args)))

(defn uglify-css [site {:contents contents}]
  (sh/$< echo ,(string contents) | yuicompressor --type css))

(def site {:logo {:some :logo :dest logo-path}
           :static {:each :static
                    :dest (bagatto/path-copier "static")}
           :css {:each :css
                 :dest (bagatto/path-copier "static")
                 :out uglify-css}
           :index {:dest index-path
                   :out (renderer "/templates/site" {:show-logo? true})}
           :getting {:dest getting-path
                     :out (renderer "/templates/getting")}
           :guides {:dest guides-path
                    :out (renderer "/templates/guides")}
           :guide {:each :guides
                   :dest guide-path
                   :out (renderer "/templates/guide" {:root "../"})}
           :api {:dest api-path
                 :out (renderer "/templates/api")}
           :manual {:dest manual-path
                    :out (renderer "/templates/manual")}
           :builds {:each :builds
                    :dest build-path} })