-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.ts
61 lines (50 loc) · 1.34 KB
/
contentlayer.config.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
61
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
interface BibleFields {
date: string
year: number
month: number
day: number
title: string
}
const createPathParser = () => {
const cache = new Map()
return (doc: any): BibleFields => {
const path = doc._raw.flattenedPath
if (cache.has(path)) return cache.get(path)
const [date, ...splitTitle] = path.split('_')
const [year, month, day] = date.split('/').map(Number)
const title = splitTitle.join('\n')
const result = { date, year, month: month - 1, day, title }
cache.set(path, result)
return result
}
}
const pathParser = createPathParser()
export const Bible = defineDocumentType(() => ({
name: 'Bible',
filePathPattern: `[0-9][0-9][0-9][0-9]/([0-9]|[0-9][0-9])/*.md`,
fields: {},
computedFields: {
date: {
type: 'string',
resolve: (doc) => pathParser(doc).date,
},
year: {
type: 'number',
resolve: (doc) => pathParser(doc).year,
},
month: {
type: 'number',
resolve: (doc) => pathParser(doc).month,
},
day: {
type: 'number',
resolve: (doc) => pathParser(doc).day,
},
title: {
type: 'string',
resolve: (doc) => pathParser(doc).title,
},
},
}))
export default makeSource({ contentDirPath: 'bible', documentTypes: [Bible] })