~subsetpark/bagatto

ref: 4fc04b3afee0f496217a3243a75f75d51d5b64f1 bagatto/main.janet -rw-r--r-- 1.7 KiB
4fc04b3a — Zach Smith Add render some 7 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
(import temple)
(import argparse :prefix "")

(import /src/core)
(import /src/error)
(import /src/env)
(import /repl)

(defn- index-value
  [env sym index]
  (try ((env sym) :value)
    ([err fib] (propagate (error/eval-error sym index) fib))))

(defn- prepare-env [index]
  (-> index
      (dofile)))

(def argparse-params ["A transparent, extensible static site generator."
                      "repl" {:kind :flag
                              :help "Compile your index module and enter the REPL."}
                      :default {:kind
                                :option
                                :help "The index module to evaluate."
                                :required true}])

(def repl-env
  ```
  An environment including the `repl` module, for interactive development.
  ```
  (require "/repl"))

(defn main [& args]
  (merge-into root-env core/bagatto)
  (env/prepare-root-env!)

  (when-let [args (argparse ;argparse-params)]
    (let [index (args :default)
          env (prepare-env index)]

      (merge-into temple/base-env env)

      (if (args "repl")
        # REPL mode: Enter a REPL to experiment with the contents of the
        # index module.
        (do
          (merge-into env repl-env)
          (repl nil nil env))
        # Normal mode: evaluate index module and write site.
        (do (setdyn :bagatto-defaults (env :bagatto-defaults))

          (def data (let [data-spec (index-value env 'data index)]
                      (core/load-data data-spec env)))

          (def writer-specs (let [site-spec (index-value env 'site index)]
                              (core/produce-writer-specs site-spec data env)))

          (core/evaluate-writer-specs env writer-specs))))))