@vercel/geistdocs 2.15.4 → 2.16.0-canary.abbda54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/internal/navbar/mobile-menu.d.ts +3 -3
- package/dist/internal/navbar/mobile-menu.d.ts.map +1 -1
- package/dist/internal/navbar/mobile-menu.js +3 -3
- package/dist/internal/navbar/navbar-logo.d.ts +5 -3
- package/dist/internal/navbar/navbar-logo.d.ts.map +1 -1
- package/dist/internal/navbar/navbar-logo.js +71 -14
- package/dist/navbar.js +4 -3
- package/dist/next.d.ts +15 -2
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +27 -5
- package/dist/routes/search.d.ts +8 -1
- package/dist/routes/search.d.ts.map +1 -1
- package/dist/routes/search.js +120 -82
- package/dist/source-config.d.ts +2 -0
- package/dist/source-config.d.ts.map +1 -1
- package/dist/source-config.js +2 -0
- package/docs/agents.md +1 -1
- package/docs/llms.txt +84 -2
- package/docs/manifest.json +1 -1
- package/docs/pages/configuration.md +83 -1
- package/package.json +22 -9
- package/rehype-code-highlights.d.ts +13 -0
- package/rehype-code-highlights.js +278 -0
- package/search-index.d.ts +14 -0
- package/search-index.js +447 -0
- package/source-config-public.d.ts +15 -0
- package/source-config-public.js +47 -0
- package/source-config.js +2 -0
- package/template/AGENTS.md +4 -0
- package/template/app/api/search/route.ts +7 -2
- package/template/content/docs/configuration.mdx +83 -1
- package/template/lib/geistdocs/search-source.ts +6 -0
- package/template/next.config.ts +1 -1
- package/template/package.json +1 -1
- package/template/source.config.ts +1 -1
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { codeToTokens, isSupportedLanguage } from "@pierre/highlights";
|
|
2
|
+
import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
|
|
3
|
+
import {
|
|
4
|
+
rehypeCodeDefaultOptions,
|
|
5
|
+
transformerIcon,
|
|
6
|
+
transformerTab,
|
|
7
|
+
} from "fumadocs-core/mdx-plugins";
|
|
8
|
+
import { tokensToHast, transformerDecorations } from "shiki/core";
|
|
9
|
+
|
|
10
|
+
// Highlights code blocks with @pierre/highlights (hand-written
|
|
11
|
+
// Wasm lexers) instead of Shiki's TextMate grammars, while keeping Shiki's
|
|
12
|
+
// HAST output and transformer pipeline so Fumadocs' code block features
|
|
13
|
+
// (titles, icons, tabs, line notation, diffs, focus) keep working.
|
|
14
|
+
|
|
15
|
+
const v = (name) => `token-${name}`;
|
|
16
|
+
|
|
17
|
+
// Maps Highlights' Zed token names onto the same CSS variables the Geist
|
|
18
|
+
// Shiki theme uses (see `geistShikiTheme`), so the existing palette applies.
|
|
19
|
+
// With a `cssVariables` palette, colors are variable suffixes: `token-keyword`
|
|
20
|
+
// renders as `var(--shiki-token-keyword)`.
|
|
21
|
+
export const geistHighlightsTheme = {
|
|
22
|
+
name: "geist",
|
|
23
|
+
appearance: "light",
|
|
24
|
+
cssVariables: {
|
|
25
|
+
prefix: "--shiki-",
|
|
26
|
+
defaults: { "color-text": "inherit", "color-background": "transparent" },
|
|
27
|
+
},
|
|
28
|
+
style: {
|
|
29
|
+
"editor.foreground": "color-text",
|
|
30
|
+
"editor.background": "color-background",
|
|
31
|
+
syntax: {
|
|
32
|
+
comment: v("comment"),
|
|
33
|
+
"comment.doc": v("comment"),
|
|
34
|
+
"keyword.jsdoc": v("comment"),
|
|
35
|
+
"type.jsdoc": v("comment"),
|
|
36
|
+
"variable.jsdoc": v("comment"),
|
|
37
|
+
constant: v("constant"),
|
|
38
|
+
"constant.builtin": v("constant"),
|
|
39
|
+
boolean: v("constant"),
|
|
40
|
+
number: v("constant"),
|
|
41
|
+
enum: v("constant"),
|
|
42
|
+
"variable.special": v("constant"),
|
|
43
|
+
function: v("function"),
|
|
44
|
+
"function.definition": v("function"),
|
|
45
|
+
"function.method": v("function"),
|
|
46
|
+
constructor: v("function"),
|
|
47
|
+
type: v("function"),
|
|
48
|
+
"type.class": v("function"),
|
|
49
|
+
tag: v("function"),
|
|
50
|
+
"tag.jsx": v("function"),
|
|
51
|
+
"tag.component.jsx": v("function"),
|
|
52
|
+
"tag.doctype": v("function"),
|
|
53
|
+
title: v("function"),
|
|
54
|
+
namespace: v("function"),
|
|
55
|
+
selector: v("function"),
|
|
56
|
+
"selector.class": v("function"),
|
|
57
|
+
"selector.id": v("function"),
|
|
58
|
+
"selector.pseudo": v("function"),
|
|
59
|
+
attribute: v("constant"),
|
|
60
|
+
"attribute.jsx": v("constant"),
|
|
61
|
+
"variable.parameter": v("parameter"),
|
|
62
|
+
property: v("parameter"),
|
|
63
|
+
"property.json_key": v("parameter"),
|
|
64
|
+
label: v("parameter"),
|
|
65
|
+
"text.jsx": v("parameter"),
|
|
66
|
+
"punctuation.list_marker": v("parameter"),
|
|
67
|
+
keyword: v("keyword"),
|
|
68
|
+
"keyword.control": v("keyword"),
|
|
69
|
+
"keyword.declaration": v("keyword"),
|
|
70
|
+
"keyword.import": v("keyword"),
|
|
71
|
+
"keyword.operator": v("keyword"),
|
|
72
|
+
operator: v("keyword"),
|
|
73
|
+
preproc: v("keyword"),
|
|
74
|
+
string: v("string"),
|
|
75
|
+
"string.escape": v("string"),
|
|
76
|
+
"string.special": v("string"),
|
|
77
|
+
"string.special.symbol": v("string"),
|
|
78
|
+
"text.literal": v("string"),
|
|
79
|
+
"string.regex": v("string-expression"),
|
|
80
|
+
punctuation: v("punctuation"),
|
|
81
|
+
"punctuation.bracket": v("punctuation"),
|
|
82
|
+
"punctuation.delimiter": v("punctuation"),
|
|
83
|
+
"punctuation.special": v("keyword"),
|
|
84
|
+
"punctuation.markup": v("punctuation"),
|
|
85
|
+
"punctuation.bracket.html": v("parameter"),
|
|
86
|
+
"punctuation.bracket.jsx": v("parameter"),
|
|
87
|
+
"punctuation.delimiter.html": v("parameter"),
|
|
88
|
+
"punctuation.delimiter.jsx": v("parameter"),
|
|
89
|
+
link_uri: v("link"),
|
|
90
|
+
link_text: v("parameter"),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Fenced-code names that Highlights doesn't know but Shiki users write.
|
|
96
|
+
const LANG_ALIASES = {
|
|
97
|
+
plaintext: "plain",
|
|
98
|
+
txt: "plain",
|
|
99
|
+
"": "plain",
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const resolveLang = (lang) => {
|
|
103
|
+
const name = LANG_ALIASES[lang] ?? lang ?? "plain";
|
|
104
|
+
return isSupportedLanguage(name) ? name : "plain";
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const TRAILING_NEWLINE = /\n$/;
|
|
108
|
+
|
|
109
|
+
const ENFORCE_ORDER = { pre: 0, undefined: 1, post: 2 };
|
|
110
|
+
|
|
111
|
+
const getTransformers = (options) => [
|
|
112
|
+
...[...(options.transformers ?? [])].sort(
|
|
113
|
+
(a, b) => ENFORCE_ORDER[a.enforce] - ENFORCE_ORDER[b.enforce]
|
|
114
|
+
),
|
|
115
|
+
transformerDecorations(),
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const UNSTYLED = "var(--shiki-foreground)";
|
|
119
|
+
const COMMENT = "var(--shiki-token-comment)";
|
|
120
|
+
const TRAILING_SPACE = /[\t ]+$/;
|
|
121
|
+
|
|
122
|
+
const joinCommentWhitespace = (line) => {
|
|
123
|
+
for (let index = 1; index < line.length; index++) {
|
|
124
|
+
const token = line[index];
|
|
125
|
+
if (token.htmlStyle?.color !== COMMENT) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
// Shiki groups JSX indentation with the opening brace. Its annotation
|
|
129
|
+
// transformer recognizes a standalone JSX comment by those three tokens.
|
|
130
|
+
const opening = index - 1;
|
|
131
|
+
if (
|
|
132
|
+
token.content.trimStart().startsWith("/*") &&
|
|
133
|
+
line[opening].content.trim() === "{" &&
|
|
134
|
+
line[index + 1]?.content.trim() === "}" &&
|
|
135
|
+
line.slice(0, opening).every((part) => part.content.trim() === "")
|
|
136
|
+
) {
|
|
137
|
+
const indentation = line
|
|
138
|
+
.slice(0, opening)
|
|
139
|
+
.map((part) => part.content)
|
|
140
|
+
.join("");
|
|
141
|
+
line[opening].content = indentation + line[opening].content;
|
|
142
|
+
line[opening].offset -= indentation.length;
|
|
143
|
+
line.splice(0, opening);
|
|
144
|
+
index -= opening;
|
|
145
|
+
}
|
|
146
|
+
// Shiki includes the separator before a comment in its comment token.
|
|
147
|
+
// Match that boundary so notation removal also removes the separator,
|
|
148
|
+
// without trimming authored whitespace from unrelated code lines.
|
|
149
|
+
while (index > 0) {
|
|
150
|
+
const previous = line[index - 1];
|
|
151
|
+
const whitespace = previous.content.match(TRAILING_SPACE)?.[0];
|
|
152
|
+
if (!whitespace) {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
previous.content = previous.content.slice(0, -whitespace.length);
|
|
156
|
+
token.content = whitespace + token.content;
|
|
157
|
+
token.offset -= whitespace.length;
|
|
158
|
+
if (previous.content) {
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
line.splice(index - 1, 1);
|
|
162
|
+
index--;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const tokenize = (code, options) => {
|
|
168
|
+
const result = codeToTokens(code, {
|
|
169
|
+
lang: resolveLang(options.lang),
|
|
170
|
+
themes: { light: geistHighlightsTheme },
|
|
171
|
+
defaultColor: "light",
|
|
172
|
+
cssVariablePrefix: "--shiki-",
|
|
173
|
+
});
|
|
174
|
+
// Highlights colors unstyled runs with `var(--shiki-foreground)`; Shiki uses
|
|
175
|
+
// the theme foreground, which Geist defines as `--shiki-color-text`.
|
|
176
|
+
for (const line of result.tokens) {
|
|
177
|
+
joinCommentWhitespace(line);
|
|
178
|
+
for (const token of line) {
|
|
179
|
+
if (token.htmlStyle?.color === UNSTYLED) {
|
|
180
|
+
token.htmlStyle = { ...token.htmlStyle, color: result.fg };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
tokens: result.tokens,
|
|
186
|
+
fg: result.fg,
|
|
187
|
+
bg: result.bg,
|
|
188
|
+
themeName: "shiki-themes geist",
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* A minimal Shiki highlighter: enough of the API for `@shikijs/rehype/core`.
|
|
194
|
+
* Mirrors Shiki's `codeToHast` (preprocess → tokens → token transformers →
|
|
195
|
+
* `tokensToHast`), swapping the tokenizer for Highlights.
|
|
196
|
+
*/
|
|
197
|
+
export const highlightsShikiAdapter = {
|
|
198
|
+
getLoadedLanguages: () => [],
|
|
199
|
+
loadLanguage: async () => undefined,
|
|
200
|
+
codeToTokens: (code, options) => tokenize(code, options),
|
|
201
|
+
codeToHast(code, options) {
|
|
202
|
+
const transformers = getTransformers(options);
|
|
203
|
+
const context = {
|
|
204
|
+
meta: {},
|
|
205
|
+
options,
|
|
206
|
+
codeToHast: (c, o) => highlightsShikiAdapter.codeToHast(c, o),
|
|
207
|
+
codeToTokens: (c, o) => tokenize(c, o),
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
let input = code;
|
|
211
|
+
for (const transformer of transformers) {
|
|
212
|
+
input = transformer.preprocess?.call(context, input, options) || input;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let { tokens, fg, bg, themeName } = tokenize(input, options);
|
|
216
|
+
const contextSource = {
|
|
217
|
+
...context,
|
|
218
|
+
get source() {
|
|
219
|
+
return input;
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
for (const transformer of transformers) {
|
|
223
|
+
tokens = transformer.tokens?.call(contextSource, tokens) || tokens;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return tokensToHast(
|
|
227
|
+
tokens,
|
|
228
|
+
{
|
|
229
|
+
...options,
|
|
230
|
+
fg,
|
|
231
|
+
bg,
|
|
232
|
+
themeName,
|
|
233
|
+
transformers: options.transformers,
|
|
234
|
+
},
|
|
235
|
+
contextSource
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/** Drop-in for Fumadocs' `rehypeCode`, backed by @pierre/highlights. */
|
|
241
|
+
export const rehypeCodeHighlights = (userOptions = {}) => {
|
|
242
|
+
const options = { ...rehypeCodeDefaultOptions, ...userOptions };
|
|
243
|
+
const transformers = [...(options.transformers ?? [])];
|
|
244
|
+
|
|
245
|
+
// Same preprocessing as Fumadocs' rehypeCode.
|
|
246
|
+
transformers.unshift({
|
|
247
|
+
name: "rehype-code:pre-process",
|
|
248
|
+
preprocess(code, { meta }) {
|
|
249
|
+
if (meta && "__parsed_raw" in meta) {
|
|
250
|
+
meta.__raw = meta.__parsed_raw;
|
|
251
|
+
// biome-ignore lint/performance/noDelete: matches Fumadocs.
|
|
252
|
+
delete meta.__parsed_raw;
|
|
253
|
+
}
|
|
254
|
+
if (meta && options.filterMetaString) {
|
|
255
|
+
meta.__raw = options.filterMetaString(meta.__raw ?? "");
|
|
256
|
+
}
|
|
257
|
+
return code.replace(TRAILING_NEWLINE, "");
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
if (options.icon !== false) {
|
|
261
|
+
transformers.push(transformerIcon(options.icon));
|
|
262
|
+
}
|
|
263
|
+
if (options.tab !== false) {
|
|
264
|
+
transformers.push(transformerTab());
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// `lazy` routes every language through `loadLanguage`, which is a no-op:
|
|
268
|
+
// Highlights bundles its lexers and unknown languages fall back to plain.
|
|
269
|
+
const transformer = rehypeShikiFromHighlighter(highlightsShikiAdapter, {
|
|
270
|
+
...options,
|
|
271
|
+
lazy: true,
|
|
272
|
+
transformers,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
return async (tree, file) => {
|
|
276
|
+
await transformer(tree, file, () => undefined);
|
|
277
|
+
};
|
|
278
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { defineConfig } from "fumadocs-mdx/config";
|
|
2
|
+
/** Generates search-only collections in .source/search before bundling. */
|
|
3
|
+
export declare const searchIndex: () => NonNullable<
|
|
4
|
+
NonNullable<Parameters<typeof defineConfig>[0]>["plugins"]
|
|
5
|
+
>[number];
|
|
6
|
+
|
|
7
|
+
/** Internal Next integration: await generation and surface extraction failures. */
|
|
8
|
+
export declare const prepareSearchIndex: (
|
|
9
|
+
options?: import("fumadocs-mdx/next").CreateMDXOptions
|
|
10
|
+
) => Promise<void>;
|
|
11
|
+
|
|
12
|
+
export declare const skipSearchIndexGeneration: (
|
|
13
|
+
options?: import("fumadocs-mdx/next").CreateMDXOptions
|
|
14
|
+
) => void;
|