-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentlayer.config.ts
150 lines (144 loc) · 3.11 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import {
defineDocumentType,
defineNestedType,
makeSource,
} from 'contentlayer2/source-files';
import highlight from 'rehype-highlight';
import slug from 'slug';
const Image = defineNestedType(() => ({
name: 'Image',
fields: {
src: { type: 'string', required: true },
alt: { type: 'string', required: true },
height: { type: 'number' },
width: { type: 'number' },
},
}));
export const Project = defineDocumentType(() => ({
name: 'Project',
filePathPattern: 'projects/*.md',
fields: {
title: {
type: 'string',
description: 'The title of the project',
required: true,
},
subtitle: {
type: 'string',
description: 'A subtitle to describe the project',
},
url: {
type: 'string',
description: 'An external URL to link to the project',
required: true,
},
image: {
type: 'nested',
of: Image,
description: 'An image to represent the project',
required: true,
},
},
computedFields: {
slug: {
type: 'string',
resolve: (post) => slug(post.title),
},
},
}));
const Tag = defineNestedType(() => ({
name: 'Tag',
fields: {
title: { type: 'string', required: true },
},
}));
export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: 'posts/*.mdx',
contentType: 'mdx',
fields: {
title: {
type: 'string',
description: 'The title of the post',
required: true,
},
description: {
type: 'string',
description: 'A short description of the post content',
required: true,
},
status: {
type: 'enum',
options: ['Draft', 'Published'],
description: 'The publishing status of the post',
required: true,
},
date: {
type: 'date',
required: true,
},
image: {
type: 'nested',
of: Image,
description: 'An image to represent the post',
required: true,
},
ogImage: {
type: 'nested',
of: Image,
description:
'A portrait image which will be used within the OG share image if present',
required: false,
},
tags: {
type: 'list',
of: Tag,
required: true,
},
},
computedFields: {
slug: {
type: 'string',
resolve: (post) => slug(post.title),
},
},
}));
export const Link = defineDocumentType(() => ({
name: 'Link',
filePathPattern: 'links/*.mdx',
contentType: 'mdx',
fields: {
name: {
type: 'string',
description: 'The name of the external website',
required: true,
},
description: {
type: 'string',
description: 'Text to describe where the link will take the reader',
required: true,
},
url: {
type: 'string',
required: true,
},
source: {
type: 'enum',
options: ['internal', 'external'],
required: true,
},
destinationType: {
type: 'enum',
options: ['social', 'code'],
required: true,
},
},
}));
export default makeSource({
contentDirPath: 'content',
documentTypes: [Project, Post, Link],
mdx: {
// @ts-ignore
rehypePlugins: [highlight],
},
});