This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
contentlayer.config.js
113 lines (109 loc) · 3.13 KB
/
contentlayer.config.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
import { imageMetadata } from './lib/images'
import rehypePrism from 'rehype-prism-plus'
import remarkGfm from 'remark-gfm'
import remarkSmartypants from 'remark-smartypants'
import remarkUnwrapImages from 'remark-unwrap-images'
export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: `blog/*.md`,
contentType: 'mdx',
fields: {
title: {
type: 'string',
description: 'The title of the post',
required: true,
},
description: {
type: 'string',
description: 'The description of the post',
required: false,
},
date: {
type: 'date',
description: 'The date of the post',
required: true,
},
featuredImage: {
type: 'string',
description: 'The featured image of the post',
required: false,
},
colorMode: {
type: 'string',
description: 'The color mode of the post, default to light',
required: false,
},
},
computedFields: {
day: {
type: 'string',
description: 'The day of the post derived from the filename.',
resolve: (source) => source._raw.sourceFileName.substring(8, 10),
},
month: {
type: 'string',
description: 'The month of the post derived from the filename.',
resolve: (source) => source._raw.sourceFileName.substring(5, 7),
},
year: {
type: 'string',
description: 'The year of the post derived from the filename.',
resolve: (source) => source._raw.sourceFileName.substring(0, 4),
},
slug: {
type: 'string',
description: 'The slug of the post derived from the filename.',
resolve: (source) =>
source._raw.sourceFileName.replace(/\.md$/, '').substring(11),
},
},
}))
export const MicroBlog = defineDocumentType(() => ({
name: 'MicroBlog',
filePathPattern: `microblog/*.md`,
contentType: 'mdx',
fields: {
title: {
type: 'string',
description: 'The title of the post',
required: false,
},
date: {
type: 'date',
description: 'The date of the post',
required: true,
},
},
computedFields: {
day: {
type: 'string',
description: 'The day of the post derived from the filename.',
resolve: (source) => source._raw.sourceFileName.substring(8, 10),
},
month: {
type: 'string',
description: 'The month of the post derived from the filename.',
resolve: (source) => source._raw.sourceFileName.substring(5, 7),
},
year: {
type: 'string',
description: 'The year of the post derived from the filename.',
resolve: (source) => source._raw.sourceFileName.substring(0, 4),
},
slug: {
type: 'string',
description: 'The slug of the post derived from the filename.',
resolve: (source) =>
source._raw.sourceFileName.replace(/\.md$/, '').substring(11),
},
},
}))
export default makeSource({
contentDirPath: 'content',
documentTypes: [Post, MicroBlog],
mdx: {
remarkPlugins: [remarkUnwrapImages, remarkSmartypants, remarkGfm],
rehypePlugins: [rehypePrism, imageMetadata],
},
})