Skip to content

Commit f391ea4

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

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

lib/data/event_categories.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 normalizeEventCategories(categories) {
5-
const md = await getVitepressMd()
6-
7-
for (const [k, v] of Object.entries(categories)) {
8-
v.description = md.renderInline(v.description)
9-
}
10-
11-
return categories
12-
}
1+
import { loadEventCategories } from '../event_categories.js'
2+
import { addWatchPaths } from '../utility.js'
133

144
export default addWatchPaths({
155
async load() {
16-
return await normalizeEventCategories(
17-
structuredClone(loadData('event_categories').categories)
18-
)
6+
return await loadEventCategories()
197
}
208
})

lib/event_categories.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 normalizeEventCategories(categories) {
5+
const md = await getVitepressMd()
6+
7+
for (const [k, v] of Object.entries(categories)) {
8+
v.description = md.renderInline(v.description)
9+
}
10+
11+
return categories
12+
}
13+
14+
export async function loadEventCategories() {
15+
return await normalizeEventCategories(
16+
structuredClone(loadData('event_categories').categories)
17+
)
18+
}

0 commit comments

Comments
 (0)