-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.js
128 lines (124 loc) · 2.84 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import rehypeSlug from "rehype-slug";
import rehypePrettyCode from "rehype-pretty-code";
import readingTime from "reading-time";
/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
urlslug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`.toLowerCase(),
},
slugAsParams: {
type: "string",
resolve: (doc) =>
doc._raw.flattenedPath.split("/").slice(1).join("/").toLowerCase(),
},
readingTime: {
type: "json",
resolve: (doc) => readingTime(doc.body.raw, { wordsPerMinute: 500 }),
},
headings: {
type: "json",
resolve: async (doc) => {
const regXHeader = /\n(?<flag>#{2,6})\s+(?<content>.+)/g;
const headings = Array.from(doc.body.raw.matchAll(regXHeader)).map(
({ groups }) => {
const flag = groups?.flag;
const content = groups?.content;
return {
level:
flag?.length == 1 ? "one" : flag?.length == 2 ? "two" : "three",
text: content,
id: content.split(" ").join("-").toLowerCase(),
};
}
);
return headings;
},
},
};
export const Page = defineDocumentType(() => ({
name: "Page",
filePathPattern: `pages/**/*.md`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
},
computedFields,
}));
export const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `blog/**/*.md`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
pubDate: {
type: "date",
required: true,
},
updatedDate: {
type: "date",
required: false,
},
image: {
type: "string",
default: "",
},
draft: {
type: "boolean",
default: false,
required: false,
},
featured: {
type: "boolean",
default: false,
required: false,
},
categories: {
type: "list",
default: [],
of: { type: "string" },
},
tags: {
type: "list",
default: [],
of: { type: "string" },
},
imageDesc: {
type: "string",
default: "",
},
},
computedFields,
}));
export default makeSource({
contentDirPath: "./data/content",
documentTypes: [Post, Page],
mdx: {
remarkPlugins: [remarkGfm, remarkMath],
rehypePlugins: [
[rehypePrettyCode, { theme: "github-dark-dimmed", keepBackground: true }],
rehypeKatex,
rehypeSlug,
],
},
});