-
Notifications
You must be signed in to change notification settings - Fork 8
/
contentlayer.config.js
57 lines (55 loc) · 1.31 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
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import rehypeSlug from "rehype-slug";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import remarkCodeTitles from "remark-code-titles";
import mdxPrism from "mdx-prism";
import readingTime from "reading-time";
export const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
excerpt: {
type: "string",
required: true,
},
date: {
type: "string",
required: true,
},
image: {
type: "string",
},
},
computedFields: {
slug: {
type: "string",
resolve: (post) => `${post._raw.flattenedPath}`,
},
tweetIds: {
type: "array",
resolve: (post) => {
const tweetMatches = post.body.raw.match(
/<StaticTweet\sid="[0-9]+"\s\/>/g
);
return tweetMatches?.map((tweet) => tweet.match(/[0-9]+/g)[0]);
},
},
readTime: {
type: "number",
resolve: (post) => readingTime(post.body.raw).minutes,
},
},
}));
export default makeSource({
contentDirPath: "_posts",
documentTypes: [Post],
mdx: {
remarkPlugins: [remarkCodeTitles],
rehypePlugins: [rehypeSlug, mdxPrism],
},
});