-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.config.ts
More file actions
101 lines (95 loc) · 3.13 KB
/
source.config.ts
File metadata and controls
101 lines (95 loc) · 3.13 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
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)
* - Encodes http-method/http-target into a special title format for the pre component
*/
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;
}
}
// Encode http-method/http-target into title so it survives Shiki.
// Format: title="__http:METHOD:target_url" — decoded in the pre component.
if (node.meta) {
const methodMatch = node.meta.match(/http-method="([^"]*)"/);
const targetMatch = node.meta.match(/http-target="([^"]*)"/);
if (methodMatch || targetMatch) {
const method = methodMatch?.[1] ?? '';
const target = targetMatch?.[1] ?? '';
// Remove http-method/http-target from meta and inject as title
node.meta = node.meta
.replace(/http-method="[^"]*"/, '')
.replace(/http-target="[^"]*"/, '')
.replace(/title="[^"]*"/, '') // remove any existing title
.trim();
node.meta = `title="__http:${method}:${target}" ${node.meta}`.trim();
}
}
});
};
}
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',
'graphql',
],
},
},
});