|
1 |
| -import { addWatchPaths, loadData, normalizeArrayData } from '../utility.js' |
2 |
| -import { getVitepressMd } from '../markdown.js' |
3 |
| - |
4 |
| -/* Take the events list and normalize entries and process inheritance. */ |
5 |
| -function processInherit(i, ob) { |
6 |
| - let fields = {} |
7 |
| - |
8 |
| - if (i in ob.events) { |
9 |
| - fields = { ...fields, ...normalizeEventsFields(ob.events[i].fields) } |
10 |
| - if (ob.events[i].inherit) { |
11 |
| - fields = { ...fields, ...processInheritList(ob.events[i].inherit, ob) } |
12 |
| - } |
13 |
| - } else if (i in ob.inherits) { |
14 |
| - fields = { ...fields, ...normalizeEventsFields(ob.inherits[i].fields) } |
15 |
| - if (ob.inherits[i].inherit) { |
16 |
| - fields = { ...fields, ...processInheritList(ob.inherits[i].inherit, ob) } |
17 |
| - } |
18 |
| - } |
19 |
| - |
20 |
| - return fields |
21 |
| -} |
22 |
| - |
23 |
| -function processInheritList(i_list, ob) { |
24 |
| - /* Normalize inherit. */ |
25 |
| - let inherit = i_list |
26 |
| - if (typeof i_list === 'string') { |
27 |
| - i_list = [ i_list ] |
28 |
| - } |
29 |
| - |
30 |
| - let fields = {} |
31 |
| - for (const i of i_list.values()) { |
32 |
| - fields = { ...fields, ...processInherit(i, ob) } |
33 |
| - } |
34 |
| - |
35 |
| - return fields |
36 |
| -} |
37 |
| - |
38 |
| -function normalizeEventsFields(fields) { |
39 |
| - let f = {} |
40 |
| - |
41 |
| - for (const[k, v] of Object.entries(fields)) { |
42 |
| - let v2 |
43 |
| - if (typeof v === 'string') { |
44 |
| - v2 = { text: v } |
45 |
| - } else { |
46 |
| - v2 = v |
47 |
| - } |
48 |
| - |
49 |
| - f[k] = { ...{ |
50 |
| - // This is a single value |
51 |
| - //added: false, |
52 |
| - // Need to normalize, as changed can be multiple values. |
53 |
| - changed: {}, |
54 |
| - // This is a single value |
55 |
| - //deleted: false, |
56 |
| - // This is a single value |
57 |
| - //deprecated: false, |
58 |
| - text: false |
59 |
| - }, ...v2} |
60 |
| - } |
61 |
| - |
62 |
| - return f |
63 |
| -} |
64 |
| - |
65 |
| -/* Return list of added/changed/deprecated/removed items, this can optionally |
66 |
| - * be prefixed with a symbol to mark up an itemization, e.g. '* '. */ |
67 |
| -function appendListOfUpdates(field, prefix = '') { |
68 |
| - let out = '' |
69 |
| - for (const f of [ 'added', 'changed', 'deprecated', 'removed' ]) { |
70 |
| - for (const update_key of Object.keys(field[f] ?? {})) { |
71 |
| - const change_content = field[f][update_key] ? |
72 |
| - `: ${field[f][update_key]}` : |
73 |
| - '' |
74 |
| - out += `\n${prefix}[[${f},${update_key}]]${change_content}` |
75 |
| - } |
76 |
| - } |
77 |
| - |
78 |
| - return out |
79 |
| -} |
80 |
| - |
81 |
| -async function normalizeEvents(events, global_inherits, inherits) { |
82 |
| - events = normalizeArrayData( |
83 |
| - events, |
84 |
| - ['tags'] |
85 |
| - ) |
86 |
| - |
87 |
| - const md = await getVitepressMd() |
88 |
| - |
89 |
| - for (const [k, v] of Object.entries(events)) { |
90 |
| - if (!v) { |
91 |
| - delete events[k] |
92 |
| - continue |
93 |
| - } |
94 |
| - |
95 |
| - /* Process inheritance. */ |
96 |
| - let fields = normalizeEventsFields(global_inherits) |
97 |
| - if (v.fields) { |
98 |
| - fields = { ...fields, ...normalizeEventsFields(v.fields) } |
99 |
| - } |
100 |
| - if (v.inherit) { |
101 |
| - const ob = { |
102 |
| - events: events, |
103 |
| - inherits: inherits, |
104 |
| - } |
105 |
| - fields = { ...fields, ...processInheritList(v.inherit, ob) } |
106 |
| - } |
107 |
| - |
108 |
| - /* Append list of changes as itemization to field's description. */ |
109 |
| - for (const [k2, v2] of Object.entries(fields)) { |
110 |
| - v2.text = md.render(`${v2.text}${appendListOfUpdates(v2, '* ')}`) |
111 |
| - } |
112 |
| - |
113 |
| - v.fields = fields |
114 |
| - |
115 |
| - /* Prefix the list of changes to the event's description. */ |
116 |
| - v.text = v.text ? md.render(`${appendListOfUpdates(v)}\n${v.text}`) : null |
117 |
| - } |
118 |
| - |
119 |
| - return events |
120 |
| -} |
| 1 | +import { addWatchPaths } from '../utility.js' |
| 2 | +import { loadEvents } from '../events.js' |
121 | 3 |
|
122 | 4 | export default addWatchPaths({
|
123 | 5 | async load() {
|
124 |
| - const data = loadData('events') |
125 |
| - return await normalizeEvents( |
126 |
| - structuredClone(data.events), |
127 |
| - structuredClone(data.global_inherits), |
128 |
| - structuredClone(data.inherits) |
129 |
| - ) |
| 6 | + return await loadEvents() |
130 | 7 | }
|
131 | 8 | })
|
0 commit comments