-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathsource.config.ts
More file actions
258 lines (256 loc) · 9.14 KB
/
Copy pathsource.config.ts
File metadata and controls
258 lines (256 loc) · 9.14 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import { readFileSync } from 'node:fs';
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';
import { metaSchema, pageSchema } from 'fumadocs-core/source/schema';
import {
rehypeCodeDefaultOptions,
remarkMdxMermaid,
remarkMdxFiles,
remarkGfm,
remarkSteps,
} from 'fumadocs-core/mdx-plugins';
import { parseCodeBlockAttributes } from 'fumadocs-core/mdx-plugins/codeblock-utils';
import { z } from 'zod';
import {
transformerMetaHighlight,
transformerMetaWordHighlight,
transformerNotationDiff,
transformerNotationFocus,
transformerNotationHighlight,
transformerNotationWordHighlight,
transformerRenderIndentGuides,
} from '@shikijs/transformers';
import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
import stringWidth from 'string-width';
import { visitParents } from 'unist-util-visit-parents';
import { withBasePath } from './src/lib/shared';
/** See: https://fumadocs.dev/docs/mdx/collections */
export const docs = defineDocs({
dir: 'content',
docs: {
schema: pageSchema
.extend({
sidebarTitle: z.string().optional(),
/** An additional badge next to the page name in the sidebar tree */
tag: z.string().optional(),
/** Special pages that are included in the navigation,
yet redirect immediately to the given external URL */
url: z.httpUrl().optional(),
/** Excludes the page from search index, yet not from LLM-generated pages */
noindex: z.coerce.boolean().default(false),
})
.transform((frontmatter) => ({
...frontmatter,
// NOTE: A tag or url must not be used with an openapi specified in the frontmatter
...(frontmatter._openapi ? { tag: undefined, url: undefined } : {}),
})),
postprocess: {
includeProcessedMarkdown: true,
},
async: true,
},
meta: {
schema: metaSchema.extend({
tag: z.string().optional(),
}),
},
});
export default defineConfig({
mdxOptions: {
// NOTE: rehypeCode automatically adds an icon based on the language meta string.
// yet, we need to add an explicit `icon` override, that would replace itself with
// the prefix of an Icon component to the tab/title text, which then will be rendered by mdx
// remarkCodeTabOptions: {
// parseMdx: true,
// },
rehypeCodeOptions: {
themes: {
light: 'one-light',
dark: 'dark-plus', // one-dark-pro is an alternative option
},
icon: {
extend: {
tolk: readFileSync('./public/logo/ton-gray.svg', 'utf8'),
},
// NOTE: by default, `lang` is the icon name, and `shortcuts` option allows the `lang` meta name map onto its icon name override.
// TODO: come up with overrides based on the `icon` meta, might require "swizzling" the CodeBlock component.
// the override might place the icon as an MDX inside the title yet disable the default icon attribution.
// alternatively, make the override go into the table directly.
},
lazy: process.env.NEXT_BUILD_TYPE === 'local' ? true : false,
langs: [
'console',
'cpp',
'd',
'diff',
'http',
'ini',
'json',
'jsonc',
'js',
'jsx',
'go',
'mdx',
'html',
'swift',
'kotlin',
'python',
'rust',
'shellscript',
'powershell',
'ts',
'tsx',
'yaml',
...['fift', 'func', 'tlb', 'tolk', 'tasm'].map((name) =>
JSON.parse(readFileSync(`./src/grammars/${name}.tmLanguage.json`, 'utf8')),
),
],
langAlias: {
mytonctrl: 'shellscript',
tact: 'text',
asm: 'tasm',
md: 'mdx',
tl: 'tlb',
env: 'ini',
circom: 'cpp',
boc: 'text',
},
transformers: [
...(rehypeCodeDefaultOptions.transformers ?? []),
transformerRenderIndentGuides({ indent: 2 }),
transformerMetaHighlight(),
transformerMetaWordHighlight(),
transformerNotationHighlight({ matchAlgorithm: 'v3' }),
transformerNotationWordHighlight({ matchAlgorithm: 'v3' }),
transformerNotationDiff({ matchAlgorithm: 'v3' }),
transformerNotationFocus({ matchAlgorithm: 'v3' }),
{
name: 'Disable copying with a noCopy attribute',
pre(pre) {
const raw = this.options?.meta?.__raw;
if (!raw) return pre;
const { attributes } = parseCodeBlockAttributes(raw, ['noCopy']);
if ('noCopy' in attributes) {
pre.properties.allowCopy = '';
}
return pre;
},
},
],
},
remarkPlugins: (v) => [
// NOTE: `title=` → `tab=` meta pre-processing in CodeGroup components,
// which should be placed before default plugins!
function remarkCodeGroup() {
return (tree) => {
visitParents(tree, (node: any) => {
if (node.type !== 'mdxJsxFlowElement' || node.name !== 'CodeGroup') return;
for (const child of node.children) {
if (child.type === 'code' && child.meta) {
child.meta = child.meta.replace(/\btitle=/, 'tab=');
}
}
});
};
},
// NOTE: sourcing `items[]` in Tabs components based on values in child Tab components,
// which should be placed before default plugins!
function remarkTabs() {
return (tree) => {
visitParents(tree, (node: any) => {
if (node.type !== 'mdxJsxFlowElement' || node.name !== 'Tabs') return;
let vals = [];
for (const child of node.children) {
if (child.type !== 'mdxJsxFlowElement' || child.name !== 'Tab') continue;
const valueAttr = (child.attributes || []).find(
// @ts-ignore
(attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'value',
);
if (!valueAttr || !valueAttr.value) continue;
vals.push(valueAttr.value);
}
if (vals.length === 0) return;
if (!node.attributes) node.attributes = [];
const existing = node.attributes.findIndex(
// @ts-ignore
(attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'items',
);
if (existing !== -1) return;
node.attributes.push({
type: 'mdxJsxAttribute',
name: 'items',
value: {
type: 'mdxJsxAttributeValueExpression',
value: `[${vals.map((v) => JSON.stringify(v)).join(', ')}]`,
data: {
estree: {
type: 'Program',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'ArrayExpression',
elements: vals.map((v) => ({
type: 'Literal',
value: v,
raw: JSON.stringify(v),
})),
},
},
],
sourceType: 'module',
},
},
},
});
});
};
},
// Default Fumadocs remark plugins
...v,
// Additional plugins
remarkMath,
[
remarkGfm,
{
singleTilde: false,
stringLength: stringWidth,
},
],
remarkMdxMermaid,
remarkMdxFiles,
remarkSteps,
function remarkRemoveMdxComments() {
return (tree: any) => {
function process(node: any) {
if (!Array.isArray(node.children)) return;
node.children = node.children.filter((child: any) => {
const isExpression =
child.type === 'mdxFlowExpression' || child.type === 'mdxTextExpression';
return !(isExpression && /^\s*\/\*[\s\S]*\*\/\s*$/.test(child.value));
});
for (const child of node.children) process(child);
}
process(tree);
};
},
],
rehypePlugins: (v) => [
// NOTE: KaTeX support should be placed before everything else!
rehypeKatex,
...v,
],
},
// See: https://github.com/fuma-nama/fumapress/blob/dev/apps/docs/press.config.tsx
// See: https://github.com/fuma-nama/fumapress/tree/dev/packages/core/src/plugins
// The following plugins are unavailable in Fumadocs directly
plugins: [
// flexsearchPlugin(), // NOTE: consider using it over Orama
// llmsPlugin(), // NOTE: using it
// takumiPlugin(), // NOTE: consider using it over Next.js's OG generation iff there's some reason to do so
// imagePlugin({ formats: ["image/webp", "image/png"] }), // NOTE: optimize images in each PR in its CI
// linkValidationPlugin(), // NOTE: it is very shallow and we require much more checks
// sitemapPlugin(), // NOTE: will be added manually
// mcpPlugin(), // NOTE: llms.txt + skill files are better, because MCP are not always picked up from the context
],
});