-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.ts
87 lines (81 loc) · 2.18 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
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
/* eslint-disable no-magic-numbers */
import { defineDocumentType, makeSource } from "contentlayer2/source-files"
import rehypeKatex from "rehype-katex"
import { rehypePrettyCode } from "rehype-pretty-code"
import remarkMath from "remark-math"
export const Content = defineDocumentType(() => ({
computedFields: {
url: {
resolve: (content) => `${content._raw.flattenedPath}`,
type: "string",
},
},
contentType: "mdx",
fields: {
category: {
description: "The category of the content",
required: true,
type: "string",
},
date: {
description: "The date of the content",
required: true,
type: "date",
},
image: {
description: "The image of the content",
required: true,
type: "string",
},
star: {
description: "How much i like this content",
required: true,
type: "string",
},
subject: {
description: "The subject of the content",
required: true,
type: "string",
},
title: {
description: "The title of the Content",
required: true,
type: "string",
},
},
filePathPattern: `**/*.mdx`,
name: "Content",
}))
// https://rehype-pretty-code.netlify.app/
const options = {
// Keep the background or use a custom background color?
keepBackground: true,
onVisitHighlightedLine(node: any) {
// Each line node by default has `class="line"`.
node.properties.className.push("highlighted")
},
onVisitHighlightedWord(node: any) {
// Each word node has no className by default.
node.properties.className = ["word"]
},
// Callback hooks to add custom logic to nodes when visiting
// them.
onVisitLine(node: any) {
// Prevent lines from collapsing in `display: grid` mode, and
// allow empty lines to be copy/pasted
if (0 === node.children.length) {
node.children = [{ type: "text", value: " " }]
}
},
// Use one of Shiki's packaged themes
// theme: "one-dark-pro",
theme: "github-dark",
}
export default makeSource({
contentDirPath: "content/logbook",
documentTypes: [Content],
mdx: {
rehypePlugins: [rehypeKatex, [rehypePrettyCode, options]],
remarkPlugins: [remarkMath],
},
})