-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsource.config.ts
More file actions
161 lines (154 loc) · 4.46 KB
/
Copy pathsource.config.ts
File metadata and controls
161 lines (154 loc) · 4.46 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { createHighlighterCore } from '@shikijs/core'
import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript'
import bash from '@shikijs/langs/bash'
import c from '@shikijs/langs/c'
import cpp from '@shikijs/langs/cpp'
import csharp from '@shikijs/langs/csharp'
import css from '@shikijs/langs/css'
import glsl from '@shikijs/langs/glsl'
import go from '@shikijs/langs/go'
import html from '@shikijs/langs/html'
import javascript from '@shikijs/langs/javascript'
import json from '@shikijs/langs/json'
import jsx from '@shikijs/langs/jsx'
import markdown from '@shikijs/langs/markdown'
import python from '@shikijs/langs/python'
import rust from '@shikijs/langs/rust'
import shellscript from '@shikijs/langs/shellscript'
import sql from '@shikijs/langs/sql'
import toml from '@shikijs/langs/toml'
import tsx from '@shikijs/langs/tsx'
import typescript from '@shikijs/langs/typescript'
import wgsl from '@shikijs/langs/wgsl'
import xml from '@shikijs/langs/xml'
import yaml from '@shikijs/langs/yaml'
import { createRehypeCode } from 'fumadocs-core/mdx-plugins/rehype-code.core'
import { defineConfig, defineDocs, frontmatterSchema } from 'fumadocs-mdx/config'
import rehypeKatex from 'rehype-katex'
import remarkMath from 'remark-math'
import { z } from 'zod'
export const posts = defineDocs({
dir: 'content/posts',
docs: {
schema: frontmatterSchema.extend({
date: z.string().or(z.date()).optional(),
tags: z.array(z.string()).default([]),
category: z.string().optional(),
}),
},
})
export const notes = defineDocs({
dir: 'content/notes',
docs: {
schema: frontmatterSchema.extend({
date: z.string().or(z.date()).optional(),
tags: z.array(z.string()).default([]),
category: z.string().optional(),
}),
},
})
const osTheme = {
name: 'os-theme',
type: 'dark' as const,
colors: {
'editor.foreground': 'var(--shiki-foreground)',
'editor.background': 'var(--shiki-background)',
},
tokenColors: [
{ scope: 'keyword', settings: { foreground: 'var(--shiki-token-keyword)' } },
{ scope: 'string', settings: { foreground: 'var(--shiki-token-string)' } },
{ scope: 'comment', settings: { foreground: 'var(--shiki-token-comment)' } },
{ scope: 'constant', settings: { foreground: 'var(--shiki-token-constant)' } },
{ scope: 'parameter', settings: { foreground: 'var(--shiki-token-parameter)' } },
{ scope: 'function', settings: { foreground: 'var(--shiki-token-function)' } },
{ scope: 'punctuation', settings: { foreground: 'var(--shiki-token-punctuation)' } },
{ scope: 'link', settings: { foreground: 'var(--shiki-token-link)' } },
],
}
function remarkMermaid() {
return (tree: any) => {
const walk = (node: any) => {
if (!node)
return
if (node.children && Array.isArray(node.children)) {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i]
if (child && child.type === 'code' && child.lang === 'mermaid') {
node.children[i] = {
type: 'mdxJsxFlowElement',
name: 'Mermaid',
attributes: [
{
type: 'mdxJsxAttribute',
name: 'chart',
value: child.value,
},
],
children: [],
}
}
else {
walk(child)
}
}
}
}
walk(tree)
}
}
const rehypeCode = createRehypeCode(async () => {
const highlighter = await createHighlighterCore({
langs: [
javascript,
typescript,
jsx,
tsx,
html,
css,
json,
markdown,
python,
c,
cpp,
csharp,
rust,
go,
sql,
toml,
yaml,
xml,
bash,
shellscript,
glsl,
wgsl,
],
themes: [osTheme],
engine: createJavaScriptRegexEngine(),
})
return {
highlighter,
options: {
themes: {
light: osTheme,
dark: osTheme,
},
},
}
})
export default defineConfig({
mdxOptions: {
remarkPlugins: [remarkMath, remarkMermaid],
rehypePlugins: (v) => {
// Filter out Fumadocs' built-in rehypeCode plugin to prevent duplicate/conflicting highlighters
const filtered = v.filter((plugin) => {
const pluginFunc = Array.isArray(plugin) ? plugin[0] : plugin
return pluginFunc !== rehypeCode
})
return [
rehypeKatex,
...filtered,
rehypeCode,
]
},
},
})