Skip to content

Commit c3feeeb

Browse files
committed
event_reasons: Abstract data parsing code out into reusable library/module
1 parent f391ea4 commit c3feeeb

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

lib/data/event_reasons.data.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
import { getVitepressMd } from '../markdown.js'
2-
import { addWatchPaths, loadData } from '../utility.js'
3-
4-
async function normalizeEventReasons(reasons) {
5-
const md = await getVitepressMd()
6-
7-
for (const [k, v] of Object.entries(reasons)) {
8-
v.description = md.renderInline(v.description)
9-
}
10-
11-
return reasons
12-
}
1+
import { addWatchPaths } from '../utility.js'
2+
import { loadEventReasons } from '../event_reasons.js'
133

144
export default addWatchPaths({
155
async load() {
16-
return await normalizeEventReasons(
17-
structuredClone(loadData('event_reasons').reasons)
18-
)
6+
return await loadEventReasons()
197
}
208
})

lib/event_reasons.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { getVitepressMd } from './markdown.js'
2+
import { loadData } from './utility.js'
3+
4+
async function normalizeEventReasons(reasons) {
5+
const md = await getVitepressMd()
6+
7+
for (const [k, v] of Object.entries(reasons)) {
8+
v.description = md.renderInline(v.description)
9+
}
10+
11+
return reasons
12+
}
13+
14+
export async function loadEventReasons() {
15+
return await normalizeEventReasons(
16+
structuredClone(loadData('event_reasons').reasons)
17+
)
18+
}

0 commit comments

Comments
 (0)