|
1 | 1 | ^{:clay {:quarto {:draft true}}} |
2 | | -(ns civitas.explorer.db |
| 2 | +(ns civitas.db |
3 | 3 | (:require [clojure.edn :as edn] |
4 | 4 | [clojure.pprint :as pprint] |
5 | 5 | [clojure.walk :as walk] |
6 | 6 | [tablecloth.api :as tc] |
7 | 7 | [clj-yaml.core :as yaml])) |
8 | 8 |
|
9 | | -(walk/postwalk |
10 | | - (fn [x] |
11 | | - (cond (map? x) (into {} x) |
12 | | - (seq? x) (into [] x) |
13 | | - :else x)) |
14 | | - (yaml/parse-string (slurp "site/_quarto.yml"))) |
15 | | - |
16 | | -;; TODO: it might be more convenient to use Quarto to gather the metadata |
17 | | -;; ``` |
18 | | -;; quarto list --to json |
19 | | -;; ``` |
| 9 | +(defn quarto [] |
| 10 | + (walk/postwalk |
| 11 | + (fn [x] |
| 12 | + (cond (map? x) (into {} x) |
| 13 | + (seq? x) (into [] x) |
| 14 | + :else x)) |
| 15 | + (yaml/parse-string (slurp "site/_quarto.yml")))) |
20 | 16 |
|
21 | 17 | (def db-file "site/db.edn") |
22 | 18 |
|
|
28 | 24 |
|
29 | 25 | (def db (atom (slurp-edn db-file))) |
30 | 26 |
|
31 | | -;; TODO: what if the front matter doesn't match existing? |
32 | | - |
33 | | -(defn set-notebooks [notebooks] |
34 | | - (->> {:notebook notebooks} |
35 | | - (reset! db) |
36 | | - (spit-edn db-file))) |
37 | | - |
38 | 27 | (defn index-by |
39 | 28 | "Return a map where a key is (f item) and a value is item." |
40 | 29 | [f coll] |
|
44 | 33 | (assoc! ret (f x) x)) |
45 | 34 | (transient {}) coll))) |
46 | 35 |
|
| 36 | +(defn author-replacements |
| 37 | + "Creates a map of author and affiliation keys to their full definition" |
| 38 | + [] |
| 39 | + (-> (mapcat @db [:author :affiliation]) |
| 40 | + (->> (index-by :id)) |
| 41 | + (update-vals #(dissoc % :id)))) |
| 42 | + |
| 43 | +(defn expand-authors |
| 44 | + "Hook for Clay to update ns metadata configuration" |
| 45 | + [config] |
| 46 | + (update config :quarto #(walk/prewalk-replace (author-replacements) %))) |
| 47 | + |
| 48 | +;; TODO: what if the front matter doesn't match existing? |
| 49 | + |
| 50 | +(defn set-notebooks [notebooks] |
| 51 | + (->> {:notebook notebooks} |
| 52 | + (reset! db) |
| 53 | + (spit-edn db-file))) |
| 54 | + |
47 | 55 | (defn notebooks-ds [] |
48 | 56 | (tc/dataset (:notebook @db))) |
49 | 57 |
|
50 | 58 | (defn notebooks [] |
51 | 59 | (:notebook @db)) |
52 | 60 |
|
53 | | -(defn authors [] |
54 | | - (tc/dataset (:author @db))) |
55 | | - |
56 | | -(defn topic-ds [] |
57 | | - (tc/dataset (:topic @db))) |
58 | | - |
59 | 61 | (defn topics [] |
60 | 62 | (:topic @db)) |
61 | 63 |
|
|
0 commit comments