-
Notifications
You must be signed in to change notification settings - Fork 2
/
contentlayer.config.js
107 lines (102 loc) · 2.19 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
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import rehypeKatex from "rehype-katex";
import remarkMath from "remark-math";
/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
readTimeMinutes: {
type: "number",
resolve: (doc) =>
((text) => {
const wordsPerMinute = 200;
const noOfWords = text.split(/\s/g).length;
const minutes = noOfWords / wordsPerMinute;
const readTime = Math.ceil(minutes);
return `${readTime} min read`;
})(doc.body.raw),
},
};
export const Page = defineDocumentType(() => ({
name: "Page",
filePathPattern: `pages/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
},
computedFields,
}));
export const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `posts/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
date: {
type: "date",
required: true,
},
tags: {
type: "list",
of: {
type: "string",
},
},
draft: {
type: "boolean",
},
archived: {
// Added archived field to mark posts as archived
type: "boolean",
default: false,
},
reference: {
// Add the new reference field
type: "string",
required: false,
},
},
computedFields,
}));
export const Thoughts = defineDocumentType(() => ({
name: "Thoughts",
filePathPattern: `thoughts/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
date: {
type: "date",
required: true,
},
},
computedFields,
}));
export default makeSource({
contentDirPath: "./content",
documentTypes: [Post, Page, Thoughts],
mdx: {
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex],
},
});