-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.js
99 lines (92 loc) · 2.75 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
import {defineDocumentType, defineNestedType, makeSource} from "contentlayer/source-files";
import remarkGfm from "remark-gfm";
import rehypeSlug from "rehype-slug";
import {visit} from "unist-util-visit";
import pluginCodeBlock from "./plugins/codeBlock";
import { rehypeComponent } from "./libs/rehype-component";
/** @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("/"),
},
url: {type: "string", resolve: (doc) => `/${doc._raw.flattenedPath}`},
}
export const Doc = defineDocumentType(() => ({
name: "Doc",
filePathPattern: `docs/**/*.mdx`,
contentType: "mdx",
fields: {
title: {type: "string", required: true},
description: {type: "string", required: false},
date: {type: "date", required: false},
},
computedFields
}));
const AuthorProperties = defineNestedType(() => ({
name: "AuthorProperties",
fields: {
name: {type: "string", required: true},
link: {type: "string", required: false},
avatar: {type: "string", required: false},
username: {type: "string", required: false},
}
}));
export const BlogPost = defineDocumentType(() => ({
name: "BlogPost",
filePathPattern: `blog/**/*.mdx`,
contentType: "mdx",
fields: {
title: {type: "string", required: true},
description: {type: "string", required: true},
date: {type: "date", required: true},
draft: {type: "boolean", required: false},
tags: { type: 'list', of: { type: 'string' } },
author: {type: "nested",of: AuthorProperties, required: false},
image: {type: "string", required: false},
},
computedFields: {
...computedFields,
// Date format June 22nd 2023
formattedDate: {
type: "string",
resolve: (doc) => {
const date = new Date(doc.date);
const options = {year: "numeric", month: "long", day: "numeric"};
return date.toLocaleDateString("en-US", options);
}
},
// add https://nextui.org to the image path
imageAsParams: {
type: "string",
resolve: (doc) => {
const image = doc.image;
if (image) {
return `https://nextui.org${image}`;
}
}
}
}
}));
export default makeSource({
contentDirPath: "./content",
documentTypes: [Doc, BlogPost],
mdx: {
remarkPlugins: [remarkGfm, pluginCodeBlock],
rehypePlugins: [
rehypeSlug,
rehypeComponent,
() => (tree) => {
visit(tree, "element", (node) => {
if (node.tagName === "code" && node.data && node.data.meta) {
node.properties.meta = node.data.meta;
}
});
},
],
},
});