-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.data.ts
60 lines (57 loc) · 1.24 KB
/
index.data.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { createContentLoader } from 'vitepress'
const pages: IndexItem[] = [
{
file: 'programming-and-motivation/index.md',
date: '2021-03-14',
},
{
file: 'elect-live/index.md',
date: '2019-03-29',
},
{
file: 'answers/2018-09-11-React-setState.md',
date: '2018-09-11',
},
{
file: 'answers/2017-11-14-JavaScript-semicolon.md',
date: '2017-11-14',
},
]
interface IndexItem {
file: string
date: string
}
export default createContentLoader(
pages.map((p) => p.file),
{
transform(rawData) {
const map = new Map(
rawData.map((page) => {
return [page.url, page]
})
)
return pages.flatMap((p) => {
const url =
'/' + p.file.replace(/\.md$/, '.html').replace(/\/index\.html$/, '/')
const pageData = map.get(url)
if (!pageData)
return [
{
url: '#',
date: '',
title: `NOT FOUND - ${url}`,
authors: [],
},
]
return [
{
url: pageData.url,
date: p.date,
title: pageData.frontmatter.title,
authors: pageData.frontmatter.authors,
},
]
})
},
}
)