-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentlayer.config.ts
43 lines (41 loc) · 1.16 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
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import { parse } from "node-html-parser";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import rehypePrismPlus from "rehype-prism-plus";
import remarkGfm from "remark-gfm";
export const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `**/*.md`,
fields: {
title: { type: "string", required: true },
date: { type: "date", required: true },
modified: { type: "date" },
},
computedFields: {
slug: {
type: "string",
resolve: (post) => post._raw.sourceFileName.slice(0, -3),
},
url: {
type: "string",
resolve: (post) => `/post/${post._raw.sourceFileName.slice(0, -3)}`,
},
category: {
type: "string",
resolve: (post) => post._raw.flattenedPath.split("/")[0],
},
preview: {
type: "string",
resolve: (post) => parse(post.body.html).textContent.slice(0, 200),
},
},
}));
export default makeSource({
contentDirPath: "posts",
documentTypes: [Post],
markdown: {
remarkPlugins: [remarkMath, remarkGfm],
rehypePlugins: [rehypeKatex, rehypePrismPlus],
},
});