-
Notifications
You must be signed in to change notification settings - Fork 3
/
contentlayer.config.ts
154 lines (148 loc) · 3.69 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
151
152
153
154
import {
defineDocumentType,
defineNestedType,
makeSource,
} from "contentlayer/source-files";
import rehypePrettycode from "rehype-pretty-code";
import remarkGfm from "remark-gfm";
import rehypeSlug from "rehype-slug";
const Docs = defineDocumentType(() => ({
name: "Docs",
filePathPattern: `docs/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the document",
required: true,
},
description: {
type: "string",
description: "The description of the document",
required: false,
},
},
computedFields: {
url: {
type: "string",
resolve: (post) => {
return "/" + post._raw.flattenedPath;
},
},
slug: {
type: "string",
resolve: (post) => {
return post._raw.flattenedPath.split("/").slice(1).join("/");
},
},
},
}));
const Meta = defineDocumentType(() => ({
name: "Meta",
filePathPattern: `docs/**/meta.json`,
contentType: "data",
fields: {
title: {
type: "string",
description: "The title of the folder",
required: false,
},
pages: {
type: "list",
of: {
type: "string",
},
description: "Pages of the folder",
default: [],
},
},
computedFields: {
url: {
type: "string",
resolve: (post) => "/" + post._raw.sourceFileDir,
},
},
}));
const Blog = defineDocumentType(() => ({
name: "Blog",
filePathPattern: "blog/*.mdx",
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the document",
required: true,
},
description: {
type: "string",
description: "The description of the document",
required: false,
},
date: {
type: "date",
description: "The release Date of the Post",
required: true,
},
image: {
type: "string",
description: "The image url (can be relative)",
required: true,
},
author: {
type: "string",
description: "The name of the author",
required: true,
},
},
computedFields: {
url: {
type: "string",
resolve: (blog) => {
return "/" + blog._raw.flattenedPath;
},
},
slug: {
type: "string",
resolve: (blog) => {
return blog._raw.flattenedPath.split("/").slice(1).join("/");
},
},
},
}));
const Author = defineNestedType(() => ({
name: "Author",
fields: {
name: { type: "string", required: true },
title: { type: "string", required: true },
icon: { type: "string", required: true },
},
}));
const BlogMeta = defineDocumentType(() => ({
name: "BlogMeta",
filePathPattern: "blog/meta.json",
contentType: "data",
fields: {
authors: {
type: "list",
of: Author,
required: true,
},
},
isSingleton: true,
}));
export default makeSource({
contentDirPath: "content",
documentTypes: [Docs, Meta, Blog, BlogMeta],
mdx: {
rehypePlugins: [
[
rehypePrettycode,
{
theme: "css-variables",
},
],
rehypeSlug,
],
remarkPlugins: [remarkGfm],
},
});