-
Notifications
You must be signed in to change notification settings - Fork 6
/
contentlayer.config.ts
132 lines (125 loc) · 2.98 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
import {
defineDocumentType,
makeSource,
LocalDocument,
defineNestedType,
} from "contentlayer/source-files";
/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
slug: {
type: "string",
// eslint-disable-next-line no-underscore-dangle
resolve: (doc: LocalDocument) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc: LocalDocument) =>
// eslint-disable-next-line no-underscore-dangle
doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
};
const Author = defineNestedType(() => ({
name: "Author",
fields: {
name: { type: "string", required: true },
image: { type: "string", required: false },
slug: { type: "string", required: false },
description: { type: "string", required: false },
},
}));
const Blog = defineDocumentType(() => ({
name: "Blog",
filePathPattern: `blog/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the blog",
required: true,
},
descriptionShort: {
type: "string",
description: "The description for the preview tile",
required: true,
},
date: {
type: "date",
description: "The date of the blog",
required: true,
},
readTime: {
type: "string",
description: "The reading time of the blog",
required: true,
},
hashTags: {
type: "list",
of: { type: "string" },
description: "The list of hashtags of the blog",
required: false,
},
author: {
type: "nested",
of: Author,
required: false,
},
image: {
type: "string",
description: "The preview image of the blog post",
required: true,
},
hero: {
type: "string",
description: "The hero image of the blog post",
required: false,
},
},
// @ts-expect-error TODO
computedFields,
}));
export const Doc = defineDocumentType(() => ({
name: "Doc",
filePathPattern: `docs/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the document",
required: true,
},
descriptionShort: {
type: "string",
description: "The description for the preview tile",
required: true,
},
date: {
type: "date",
description: "The date of the document",
required: true,
},
image: {
type: "string",
description: "The image of the doc",
required: true,
},
hero: {
type: "string",
description: "The hero image of the doc",
required: false,
},
},
// @ts-expect-error TODO
computedFields,
}));
export const Static = defineDocumentType(() => ({
name: "Static",
filePathPattern: `static/**/*.mdx`,
contentType: "mdx",
// @ts-expect-error TODO
computedFields,
}));
// eslint-disable-next-line import/no-default-export
export default makeSource({
contentDirPath: "content",
documentTypes: [Blog, Doc, Static],
});