-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-data.mjs
39 lines (36 loc) · 961 Bytes
/
collect-data.mjs
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
import fs from 'node:fs/promises'
import glob from 'fast-glob'
import matter from 'gray-matter'
function _convertDate(date = new Date().toString()) {
const json_date = new Date(date).toJSON()
return json_date.split('T')[0]
}
; (async () => {
const articleData = await Promise.all(
glob
.sync('./docs/**/*.md', {
onlyFiles: true,
objectMode: true,
ignore: [
'./docs/**/index.md',
'./docs/**/tags.md',
'./docs/**/archive.md',
'./docs/**/about.md',
],
})
.map(async (article) => {
const file = matter.read(`${article.path}`)
const { data, path } = file
data.date = _convertDate(data.date)
return {
...data,
path: path.replace(/\.md$/, '.html').replace('./docs/', ''),
}
}),
)
await fs.writeFile(
'./docs/.vitepress/post-data.json',
JSON.stringify(articleData),
'utf-8',
)
})()