-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.config.ts
More file actions
81 lines (76 loc) · 2.19 KB
/
source.config.ts
File metadata and controls
81 lines (76 loc) · 2.19 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
import { defineDocs, defineConfig, frontmatterSchema } from 'fumadocs-mdx/config';
import { remarkMdxMermaid } from 'fumadocs-core/mdx-plugins/remark-mdx-mermaid';
import { z } from 'zod';
import { visit } from 'unist-util-visit';
import type { Root } from 'mdast';
import type { Transformer } from 'unified';
const LANG_ALIASES: Record<string, string> = {
django: 'jinja',
shell: 'bash',
};
/**
* Remark plugin: normalise Docusaurus code fences for Shiki compatibility.
* - Unwraps `mdx-code-block` fences into raw MDX
* - Strips meta from language field (title="…", showLineNumbers, etc.)
* - Maps language aliases (django → jinja, shell → bash)
*/
function remarkDocusaurusCompat(): Transformer<Root> {
return (tree) => {
visit(tree, 'code', (node: any, index: number | undefined, parent: any) => {
if (node.lang === 'mdx-code-block') {
if (index !== undefined && parent) {
parent.children.splice(index, 1, {
type: 'mdxjsEsm',
value: node.value,
data: { estree: null },
});
}
return;
}
if (node.lang) {
const firstWord = node.lang.split(/\s/)[0];
if (firstWord.startsWith('title=') || firstWord.startsWith('{')) {
node.meta = node.lang;
node.lang = null;
} else {
node.meta = node.lang.slice(firstWord.length).trim() || node.meta;
node.lang = LANG_ALIASES[firstWord] ?? firstWord;
}
}
});
};
}
export const docs = defineDocs({
dir: 'content/docs',
docs: {
schema: frontmatterSchema.extend({
title: z.string().optional().default(''),
full: z.boolean().optional(),
}),
postprocess: {
includeProcessedMarkdown: true,
},
},
});
export default defineConfig({
mdxOptions: {
providerImportSource: '@/components/mdx',
remarkPlugins: [remarkDocusaurusCompat, remarkMdxMermaid],
rehypeCodeOptions: {
themes: { light: 'github-light', dark: 'github-dark' },
langs: [
'python',
'bash',
'json',
'yaml',
'javascript',
'typescript',
'jsx',
'tsx',
'html',
'css',
'sql',
],
},
},
});