-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.ts
85 lines (80 loc) · 2 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
import { slugger } from "./src/utils/slugger";
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import readingTime from "reading-time";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeSlug from "rehype-slug";
import rehypeVideo from "rehype-video";
import remarkGfm from "remark-gfm";
export const Post = defineDocumentType(() => ({
computedFields: {
readingTime: {
resolve: (doc) => readingTime(doc.body.raw),
type: "json",
},
toc: {
resolve: async (doc) => {
const regulrExp = /\n(?<flag>#{1,6})\s+(?<content>.+)/g;
const headings = Array.from(doc.body.raw.matchAll(regulrExp)).map(
({ groups }) => {
const flag = groups?.flag;
const content = groups?.content;
return {
level:
flag?.length == 1 ? "one" : flag?.length == 2 ? "two" : "three",
slug: content ? slugger(content) : undefined,
text: content,
};
},
);
return headings;
},
type: "json",
},
url: {
resolve: (post) => `/${post._raw.flattenedPath}`,
type: "string",
},
},
contentType: "mdx",
fields: {
categories: {
of: { type: "string" },
required: true,
type: "list",
},
description: {
required: true,
type: "string",
},
image: {
required: true,
type: "image",
},
isPublished: {
default: true,
type: "boolean",
},
publishedAt: {
required: true,
type: "date",
},
title: { required: true, type: "string" },
updatedAt: {
type: "date",
},
},
filePathPattern: `**/**/*.{md,mdx}`,
name: "Post",
}));
export default makeSource({
contentDirPath: "posts",
documentTypes: [Post],
mdx: {
rehypePlugins: [
rehypeSlug,
[rehypeVideo, { details: false }],
[rehypeAutolinkHeadings, { behavior: "append" }],
],
remarkPlugins: [remarkGfm],
},
});