@vercel/geistdocs 2.15.4-canary.2a54b38 → 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.
Files changed (81) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/config.d.ts +3 -3
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
  5. package/dist/internal/mdx-to-markdown.js +0 -9
  6. package/dist/internal/navbar/mobile-menu.d.ts +3 -3
  7. package/dist/internal/navbar/mobile-menu.d.ts.map +1 -1
  8. package/dist/internal/navbar/mobile-menu.js +3 -3
  9. package/dist/internal/navbar/navbar-logo.d.ts +5 -3
  10. package/dist/internal/navbar/navbar-logo.d.ts.map +1 -1
  11. package/dist/internal/navbar/navbar-logo.js +71 -14
  12. package/dist/internal/page-actions.d.ts +4 -4
  13. package/dist/internal/page-actions.d.ts.map +1 -1
  14. package/dist/internal/page-actions.js +1 -6
  15. package/dist/mdx.d.ts +25 -3
  16. package/dist/mdx.d.ts.map +1 -1
  17. package/dist/mdx.js +61 -8
  18. package/dist/navbar.js +4 -3
  19. package/dist/next.d.ts +15 -12
  20. package/dist/next.d.ts.map +1 -1
  21. package/dist/next.js +28 -86
  22. package/dist/pages/docs.d.ts +98 -5
  23. package/dist/pages/docs.d.ts.map +1 -1
  24. package/dist/pages/docs.js +250 -13
  25. package/dist/routes/search.d.ts +8 -1
  26. package/dist/routes/search.d.ts.map +1 -1
  27. package/dist/routes/search.js +120 -82
  28. package/dist/source-config.d.ts +3 -10
  29. package/dist/source-config.d.ts.map +1 -1
  30. package/dist/source-config.js +12 -21
  31. package/dist/source.d.ts +17 -6
  32. package/dist/source.d.ts.map +1 -1
  33. package/dist/source.js +75 -2
  34. package/docs/agents.md +1 -1
  35. package/docs/llms.txt +70 -14
  36. package/docs/manifest.json +1 -1
  37. package/docs/pages/configuration.md +69 -13
  38. package/package.json +20 -35
  39. package/rehype-code-highlights.d.ts +1 -1
  40. package/rehype-code-highlights.js +49 -1
  41. package/search-index.d.ts +14 -0
  42. package/search-index.js +447 -0
  43. package/source-config-public.d.ts +15 -0
  44. package/source-config-public.js +47 -0
  45. package/source-config.js +12 -27
  46. package/template/AGENTS.md +4 -0
  47. package/template/app/api/search/route.ts +7 -2
  48. package/template/content/docs/configuration.mdx +69 -13
  49. package/template/lib/geistdocs/search-source.ts +6 -0
  50. package/template/next.config.ts +1 -1
  51. package/template/package.json +4 -7
  52. package/template/source.config.ts +1 -1
  53. package/dist/internal/source-loader.d.ts +0 -28
  54. package/dist/internal/source-loader.d.ts.map +0 -1
  55. package/dist/internal/source-loader.js +0 -77
  56. package/dist/mdx-basic.d.ts +0 -27
  57. package/dist/mdx-basic.d.ts.map +0 -1
  58. package/dist/mdx-basic.js +0 -61
  59. package/dist/navigation.d.ts +0 -11
  60. package/dist/navigation.d.ts.map +0 -1
  61. package/dist/navigation.js +0 -8
  62. package/dist/pages/docs-custom.d.ts +0 -111
  63. package/dist/pages/docs-custom.d.ts.map +0 -1
  64. package/dist/pages/docs-custom.js +0 -250
  65. package/native-mdx/LICENSE-mdxjs-rs +0 -22
  66. package/native-mdx/UPSTREAM.md +0 -16
  67. package/native-mdx/binaries/darwin-arm64.node +0 -0
  68. package/native-mdx/binaries/linux-x64-gnu.node +0 -0
  69. package/native-mdx/data-entry.d.mts +0 -15
  70. package/native-mdx/data-entry.mjs +0 -97
  71. package/native-mdx/data-projection.mjs +0 -205
  72. package/native-mdx/fumadocs-adapter.mjs +0 -36
  73. package/native-mdx/index-emitter.mjs +0 -34
  74. package/native-mdx/loader-data.cjs +0 -36
  75. package/native-mdx/loader-mdx.cjs +0 -9
  76. package/native-mdx/loader-mdx.mjs +0 -419
  77. package/native-mdx/native-binding.cjs +0 -27
  78. package/native-mdx/navigation-entry.d.mts +0 -11
  79. package/native-mdx/navigation-entry.mjs +0 -136
  80. package/native-mdx/navigation-title.mjs +0 -53
  81. package/template/pnpm-workspace.yaml +0 -3
@@ -1,34 +0,0 @@
1
- const EXTENSIONS = Symbol.for("geistdocs.index-emitter.extensions");
2
-
3
- /** One wrapper for sibling entries; re-registering on config reload replaces
4
- * each extension instead of recursively wrapping another plugin's emitter. */
5
- export function extendIndexEmitter(context, name, extend) {
6
- const plugins = context.core.getPlugins();
7
- const indexes = plugins.filter((plugin) => plugin.name === "index-file");
8
- if (indexes.length === 0 && context.environment === "webpack") {
9
- return;
10
- }
11
- if (indexes.length !== 1 || typeof indexes[0].emit !== "function") {
12
- throw new Error("Content entries require one Fumadocs index-file emitter");
13
- }
14
- const index = indexes[0];
15
- let state = index.emit[EXTENSIONS];
16
- if (!state) {
17
- state = { original: index.emit, extensions: new Map() };
18
- const emit = async function () {
19
- let entries = await state.original.call(this);
20
- const active = new Set(
21
- context.core.getPlugins().map((plugin) => plugin.name)
22
- );
23
- for (const [extensionName, extension] of state.extensions) {
24
- if (active.has(extensionName)) {
25
- entries = await extension(entries);
26
- }
27
- }
28
- return entries;
29
- };
30
- emit[EXTENSIONS] = state;
31
- index.emit = emit;
32
- }
33
- state.extensions.set(name, extend);
34
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- // Experimental wrapper: point experimentalMdxLoader at this file. Ordinary MDX
4
- // stays unchanged; only generated data-entry imports carry geistdocs-data=1.
5
- module.exports = function loader(source) {
6
- if (
7
- !new URLSearchParams((this.resourceQuery ?? "").slice(1)).has(
8
- "geistdocs-data"
9
- )
10
- ) {
11
- // Rendering-only workers should not load the projection parser at all.
12
- return require("./loader-mdx.cjs").call(this, source);
13
- }
14
- const done = this.async();
15
- import("./data-projection.mjs")
16
- .then(({ createDataLoader }) => {
17
- const { parse } = require("next/dist/compiled/acorn");
18
- const delegate = require("./loader-mdx.cjs");
19
- const context = Object.create(this);
20
- context.async = () => done;
21
- return createDataLoader(
22
- delegate,
23
- parse,
24
- ({ filePath, projected, forwarded = false, reason, code }) => {
25
- // Optional diagnostics for validation builds, never enable when timing.
26
- if (process.env.GEISTDOCS_DATA_REPORT) {
27
- require("node:fs").appendFileSync(
28
- process.env.GEISTDOCS_DATA_REPORT,
29
- `${JSON.stringify({ filePath, projected, forwarded, reason, outputBytes: Buffer.byteLength(code) })}\n`
30
- );
31
- }
32
- }
33
- ).call(context, source);
34
- })
35
- .catch(done);
36
- };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- // CommonJS entry for Turbopack/webpack, like fumadocs-mdx's own shim.
3
- module.exports = function loader(source) {
4
- const callback = this.async();
5
- import("./loader-mdx.mjs").then(
6
- (mod) => mod.run.call(this, source, callback),
7
- callback
8
- );
9
- };
@@ -1,419 +0,0 @@
1
- // Webpack/Turbopack loader for MDX, backed by the native fumadocs-mdx-rs
2
- // compiler. Mirrors fumadocs-mdx's `createMdxLoader`: config, collection,
3
- // frontmatter validation, and doc plugins stay in JS (they're user code);
4
- // parsing, transforms, highlighting, and codegen run natively. Files that
5
- // use something the native pipeline doesn't cover go to fumadocs-mdx.
6
- import { createHash } from "node:crypto";
7
- import { existsSync } from "node:fs";
8
- import { readFile } from "node:fs/promises";
9
- import { createRequire } from "node:module";
10
- import path from "node:path";
11
- import { pathToFileURL } from "node:url";
12
- import { isDeepStrictEqual } from "node:util";
13
- import {
14
- buildConfig,
15
- createStandaloneConfigLoader,
16
- fumaMatter,
17
- getCore,
18
- internal,
19
- } from "./fumadocs-adapter.mjs";
20
-
21
- const require = createRequire(import.meta.url);
22
- let native;
23
- let nativeUnavailable;
24
- const reportedFallbacks = new Set();
25
-
26
- // Only binary availability errors select JS automatically. Compiler errors
27
- // remain errors, rather than silently hiding native output bugs.
28
- function getNative() {
29
- if (native || nativeUnavailable) {
30
- return native;
31
- }
32
- try {
33
- native = require(
34
- process.env.FUMADOCS_MDX_RS_BINARY ?? "./native-binding.cjs"
35
- );
36
- } catch (error) {
37
- if (
38
- process.env.FUMADOCS_MDX_RS_BINARY ||
39
- !["GEISTDOCS_NATIVE_UNAVAILABLE", "ERR_DLOPEN_FAILED"].includes(
40
- error.code
41
- )
42
- ) {
43
- throw error;
44
- }
45
- nativeUnavailable = error.message;
46
- }
47
- return native;
48
- }
49
-
50
- function reportFallback(reason, mode) {
51
- if (mode === "native") {
52
- throw new Error(`Native MDX required, but this page needs JS: ${reason}`);
53
- }
54
- if (!reportedFallbacks.has(reason)) {
55
- reportedFallbacks.add(reason);
56
- console.warn(`[geistdocs/mdx] Using JS compiler: ${reason}`);
57
- }
58
- }
59
-
60
- const configs = new Map();
61
- const compatibility = new WeakMap();
62
-
63
- // The plugin list the native pipeline implements: Geistdocs' defaults with
64
- // Highlights (`defineGeistdocsSourceConfig()`), in fumadocs-mdx's order.
65
- const NATIVE_REMARK = [
66
- ["remarkGfm"],
67
- ["remarkSteps"],
68
- ["remarkHeading", { generateToc: false }],
69
- ["remarkImage", { useImport: true }],
70
- ["remarkCodeTab"],
71
- ["remarkNpm"],
72
- ["remarkMdxMermaid"],
73
- ["remarkDetails"],
74
- ["remarkStructure", { exportAs: "structuredData" }],
75
- ];
76
- const NATIVE_REHYPE = [
77
- ["rehypeCodeHighlights"],
78
- ["rehypeTaskListLabels"],
79
- ["rehypeToc"],
80
- ];
81
- const NATIVE_OPTION_KEYS = new Set([
82
- "remarkPlugins",
83
- "rehypePlugins",
84
- "outputFormat",
85
- ]);
86
-
87
- let defaultOptions;
88
- function getDefaultOptions() {
89
- defaultOptions ??= (async () => {
90
- const bundled = new URL("../source-config.js", import.meta.url);
91
- const url = existsSync(bundled)
92
- ? bundled
93
- : pathToFileURL(require.resolve("@vercel/geistdocs/source-config"));
94
- const { defineGeistdocsSourceConfig } = await import(url.href);
95
- return buildConfig({
96
- default: defineGeistdocsSourceConfig(),
97
- }).getMDXOptions();
98
- })();
99
- return defaultOptions;
100
- }
101
- const samePlugins = (actual, expected) =>
102
- actual.length === expected.length &&
103
- actual.every((entry, index) => {
104
- const [plugin, options] = Array.isArray(entry) ? entry : [entry];
105
- const expectedEntry = expected[index];
106
- const [expectedPlugin, expectedOptions] = Array.isArray(expectedEntry)
107
- ? expectedEntry
108
- : [expectedEntry];
109
- return (
110
- plugin === expectedPlugin &&
111
- isDeepStrictEqual(options ?? {}, expectedOptions ?? {})
112
- );
113
- });
114
- const knownPreset = (actual, expected) =>
115
- actual.length === expected.length &&
116
- actual.every((entry, index) => {
117
- const plugin = Array.isArray(entry) ? entry[0] : entry;
118
- return plugin?.name === expected[index][0];
119
- });
120
-
121
- /** Why a collection's MDX options need the JS pipeline, if they do. */
122
- async function incompatibility(config, collection) {
123
- // Collection names survive config reloads; compatibility decisions must not.
124
- if (!compatibility.has(config)) {
125
- compatibility.set(config, new Map());
126
- }
127
- const reasons = compatibility.get(config);
128
- const key = collection?.name ?? "global";
129
- if (!reasons.has(key)) {
130
- const options = await config.getMDXOptions(collection, "bundler");
131
- const defaults = await getDefaultOptions();
132
- let reason = null;
133
- const extraKeys = Object.keys(options).filter(
134
- (k) => !NATIVE_OPTION_KEYS.has(k)
135
- );
136
- if (extraKeys.length > 0) {
137
- reason = `MDX options: ${extraKeys.join(", ")}`;
138
- } else if (
139
- !(
140
- knownPreset(defaults.remarkPlugins, NATIVE_REMARK) &&
141
- knownPreset(defaults.rehypePlugins, NATIVE_REHYPE)
142
- )
143
- ) {
144
- reason = "Geistdocs preset changed; native compatibility needs review";
145
- } else if (options.outputFormat !== defaults.outputFormat) {
146
- reason = "custom MDX output format";
147
- } else if (
148
- !samePlugins(options.remarkPlugins ?? [], defaults.remarkPlugins)
149
- ) {
150
- reason = "custom remark plugins";
151
- } else if (
152
- !samePlugins(options.rehypePlugins ?? [], defaults.rehypePlugins)
153
- ) {
154
- reason = "custom rehype plugins or Shiki";
155
- }
156
- reasons.set(key, reason);
157
- }
158
- return reasons.get(key);
159
- }
160
-
161
- /** The doc collection behind a `doc` or `docs` collection. */
162
- const docCollectionOf = (collection) => {
163
- if (collection?.type === "doc") {
164
- return collection;
165
- }
166
- if (collection?.type === "docs") {
167
- return collection.docs;
168
- }
169
- };
170
-
171
- async function fallback({
172
- source,
173
- development,
174
- query,
175
- compiler,
176
- filePath,
177
- state,
178
- validated,
179
- }) {
180
- const { createMdxLoader } = await internal("chunk-USWQVJWR.js");
181
- // Content fallback can happen after schema transforms. Reuse that validated
182
- // value for this call only, so user validation hooks never run twice.
183
- state.jsLoader ??= createMdxLoader(state.configLoader);
184
- const loader = validated
185
- ? createMdxLoader({
186
- ...state.configLoader,
187
- core: {
188
- ...state.configLoader.core,
189
- transformFrontmatter: () => validated.data,
190
- },
191
- })
192
- : state.jsLoader;
193
- const out = await loader.load({
194
- getSource: () => source,
195
- development,
196
- query,
197
- compiler,
198
- filePath,
199
- });
200
- return out.code;
201
- }
202
-
203
- const literal = (value) => {
204
- if (value instanceof Date) {
205
- return `new Date(${JSON.stringify(value.toISOString())})`;
206
- }
207
- if (value === undefined) {
208
- return "undefined";
209
- }
210
- return JSON.stringify(value);
211
- };
212
-
213
- async function fillNavigationTitle(matter, config, docCollection, filePath) {
214
- if (matter.data.title === "") {
215
- throw new Error(
216
- "Navigation requires a nonempty frontmatter title; omit it to use heading fallback with a compatible schema"
217
- );
218
- }
219
- if (matter.data.title != null) {
220
- return;
221
- }
222
- if (await incompatibility(config, docCollection)) {
223
- throw new Error(
224
- "Navigation requires an explicit frontmatter title when using custom MDX plugins or options"
225
- );
226
- }
227
- const { navigationTitle } = await import("./navigation-title.mjs");
228
- const title = await navigationTitle(
229
- matter.content,
230
- filePath.endsWith(".mdx") ? "mdx" : "md"
231
- );
232
- if (title !== undefined) {
233
- matter.data.title = title;
234
- }
235
- }
236
-
237
- async function getConfigState(options, development) {
238
- const key = JSON.stringify([options.configPath, options.outDir, development]);
239
- if (!configs.has(key)) {
240
- configs.set(key, {});
241
- }
242
- const state = configs.get(key);
243
- if (development) {
244
- // Imported settings can change the bundled config without changing the
245
- // source config's mtime, which is all Fumadocs checks for reloads.
246
- const compiled = await readFile(options.absoluteCompiledConfigPath);
247
- const identity = createHash("sha256").update(compiled).digest("hex");
248
- if (identity !== state.compiledConfigIdentity) {
249
- state.compiledConfigIdentity = identity;
250
- state.configLoader = undefined;
251
- state.jsLoader = undefined;
252
- }
253
- }
254
- state.configLoader ??= createStandaloneConfigLoader({
255
- core: getCore(options),
256
- buildConfig: false,
257
- mode: development ? "dev" : "production",
258
- });
259
- return state;
260
- }
261
-
262
- async function fallbackReason(filePath, config, collection) {
263
- if (filePath.endsWith(".md")) {
264
- return "plain Markdown format";
265
- }
266
- if (
267
- Object.keys(collection?.postprocess ?? {}).some(
268
- (key) => key !== "includeProcessedMarkdown"
269
- )
270
- ) {
271
- return "custom postprocess exports";
272
- }
273
- const reason = await incompatibility(config, collection);
274
- if (reason) {
275
- return reason;
276
- }
277
- if (!getNative()) {
278
- return nativeUnavailable;
279
- }
280
- }
281
-
282
- function nativeFrontmatter(value) {
283
- if (value === null) {
284
- return true;
285
- }
286
- if (typeof value === "number") {
287
- return Number.isFinite(value);
288
- }
289
- if (typeof value === "string" || typeof value === "boolean") {
290
- return true;
291
- }
292
- if (Array.isArray(value)) {
293
- return value.every(nativeFrontmatter);
294
- }
295
- if (
296
- typeof value !== "object" ||
297
- Object.getPrototypeOf(value) !== Object.prototype
298
- ) {
299
- return false;
300
- }
301
- return Object.values(value).every(nativeFrontmatter);
302
- }
303
-
304
- export async function load({
305
- source,
306
- filePath,
307
- query,
308
- development,
309
- compiler,
310
- options,
311
- }) {
312
- const mode = options.geistdocsMdxCompiler ?? "auto";
313
- if (!["auto", "native", "js"].includes(mode)) {
314
- throw new Error(`Invalid MDX compiler mode: ${mode}`);
315
- }
316
- const state = await getConfigState(options, development);
317
- const core = state.configLoader.core;
318
- const config = await state.configLoader.getConfig();
319
- const collection = query.collection
320
- ? config.getCollection(query.collection)
321
- : undefined;
322
- const docCollection = docCollectionOf(collection);
323
- const compileWithJS = (reason, validated) => {
324
- if (mode !== "js") {
325
- reportFallback(reason, mode);
326
- }
327
- return fallback({
328
- source,
329
- development,
330
- query,
331
- compiler,
332
- filePath,
333
- state,
334
- validated,
335
- });
336
- };
337
- if (mode === "js") {
338
- return compileWithJS("explicit JS mode");
339
- }
340
- if (query.only !== "frontmatter") {
341
- const reason = await fallbackReason(filePath, config, docCollection);
342
- if (reason) {
343
- return compileWithJS(reason);
344
- }
345
- }
346
- const matter = fumaMatter(source);
347
- if (docCollection) {
348
- matter.data = await core.transformFrontmatter(
349
- { collection: docCollection, filePath, source },
350
- matter.data
351
- );
352
- }
353
- if (query.only === "frontmatter") {
354
- if (query["geistdocs-navigation"] === "1") {
355
- await fillNavigationTitle(matter, config, docCollection, filePath);
356
- }
357
- return `export const frontmatter = ${JSON.stringify(matter.data)}`;
358
- }
359
-
360
- if (!nativeFrontmatter(matter.data)) {
361
- return compileWithJS("non-JSON frontmatter values", matter);
362
- }
363
-
364
- const result = native.compile(
365
- matter.content,
366
- JSON.stringify(matter.data ?? {}),
367
- {
368
- filePath,
369
- includeProcessedMarkdown:
370
- docCollection?.postprocess?.includeProcessedMarkdown === true,
371
- development,
372
- }
373
- );
374
- if (result.fallback) {
375
- return compileWithJS(result.fallback, matter);
376
- }
377
-
378
- // Doc plugins (e.g. last-modified) contribute extra exports.
379
- let code = result.code;
380
- if (docCollection) {
381
- const file = await core.transformVFile(
382
- { collection: docCollection, filePath, source },
383
- { data: {}, path: filePath, value: source }
384
- );
385
- for (const { name, value } of file.data["mdx-export"] ?? []) {
386
- code += `\nexport let ${name} = ${literal(value)};`;
387
- }
388
- }
389
- return code;
390
- }
391
-
392
- /** Webpack loader entry. */
393
- export default function loader(source) {
394
- return run.call(this, source, this.async());
395
- }
396
-
397
- /** Loader body with an explicit callback (used by the CJS shim). */
398
- export async function run(source, callback) {
399
- const options = this.getOptions();
400
- this.cacheable(true);
401
- this.addDependency(options.absoluteCompiledConfigPath);
402
- try {
403
- const query = Object.fromEntries(
404
- new URLSearchParams(this.resourceQuery.slice(1))
405
- );
406
- const code = await load({
407
- source,
408
- filePath: this.resourcePath,
409
- query,
410
- development: this.mode === "development",
411
- compiler: this,
412
- options,
413
- });
414
- callback(undefined, code);
415
- } catch (error) {
416
- error.message = `${path.relative(this.context, this.resourcePath)}: ${error.message}`;
417
- callback(error);
418
- }
419
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- const { existsSync } = require("node:fs");
4
- const path = require("node:path");
5
-
6
- const local = path.join(__dirname, "fumadocs-mdx-rs.node");
7
- const platform = `${process.platform}-${process.arch}${process.platform === "linux" ? "-gnu" : ""}`;
8
- const bundled = path.join(__dirname, "binaries", `${platform}.node`);
9
-
10
- if (existsSync(local)) {
11
- module.exports = require(local);
12
- } else {
13
- if (
14
- !existsSync(bundled) ||
15
- (process.platform === "linux" &&
16
- !process.report.getReport().header.glibcVersionRuntime)
17
- ) {
18
- const error = new Error(
19
- `Geistdocs has no native MDX binary for ${platform}. ` +
20
- "Supported: macOS arm64 and Linux x64 (glibc). " +
21
- 'Use mdxCompiler: "js" to select the JS compiler.'
22
- );
23
- error.code = "GEISTDOCS_NATIVE_UNAVAILABLE";
24
- throw error;
25
- }
26
- module.exports = require(bundled);
27
- }
@@ -1,11 +0,0 @@
1
- import type { Plugin } from "fumadocs-mdx";
2
- import type * as TypeScript from "typescript";
3
- type Parser = typeof TypeScript;
4
- /** Opt-in metadata-only navigation.ts, for synchronous collections and the native canary loader. */
5
- export declare function navigationEntryPlugin(
6
- parser: Parser | (() => Parser | Promise<Parser>)
7
- ): Plugin;
8
- export declare function createNavigationEntry(
9
- serverCode: string,
10
- parser: Parser
11
- ): { code: string; imports: number };
@@ -1,136 +0,0 @@
1
- import { extendIndexEmitter } from "./index-emitter.mjs";
2
-
3
- const MDX_EXTENSION = /\.mdx?$/;
4
- const META_EXTENSION = /\.json$/;
5
-
6
- /** Add navigation.ts to Fumadocs' existing discovery/watch lifecycle. */
7
- export function navigationEntryPlugin(typeScriptOrLoader) {
8
- let parserPromise;
9
- const getParser = () =>
10
- (parserPromise ??= Promise.resolve()
11
- .then(() =>
12
- typeof typeScriptOrLoader === "function"
13
- ? typeScriptOrLoader()
14
- : typeScriptOrLoader
15
- )
16
- .then((module) => module.default ?? module));
17
- return {
18
- name: "geistdocs-navigation-entry",
19
- config() {
20
- const collections = this.core.getConfig?.().collectionList ?? [];
21
- for (const collection of collections) {
22
- const doc = collection.type === "docs" ? collection.docs : collection;
23
- if (doc.dynamic || doc.async) {
24
- throw new Error(
25
- "Navigation entries require synchronous collections; disable docs.async and docs.dynamic"
26
- );
27
- }
28
- }
29
- extendIndexEmitter(
30
- this,
31
- "geistdocs-navigation-entry",
32
- async (entries) => {
33
- const server = entries.find((entry) => entry.path === "server.ts");
34
- if (
35
- !server ||
36
- entries.some((entry) => entry.path === "navigation.ts")
37
- ) {
38
- throw new Error(
39
- "Content entries require server.ts and an unused navigation.ts output"
40
- );
41
- }
42
- return [
43
- ...entries,
44
- {
45
- path: "navigation.ts",
46
- content: createNavigationEntry(server.content, await getParser())
47
- .code,
48
- },
49
- ];
50
- }
51
- );
52
- },
53
- };
54
- }
55
-
56
- /** Metadata queries only: no renderable MDX imports, including dynamic ones. */
57
- export function createNavigationEntry(serverCode, ts) {
58
- const file = ts.createSourceFile(
59
- "server.ts",
60
- serverCode,
61
- ts.ScriptTarget.Latest,
62
- true,
63
- ts.ScriptKind.TS
64
- );
65
- if (file.parseDiagnostics.length) {
66
- throw new Error("Cannot parse generated server entry");
67
- }
68
- const edits = [];
69
- function inspect(node) {
70
- if (
71
- ts.isMetaProperty(node) &&
72
- node.keywordToken === ts.SyntaxKind.ImportKeyword
73
- ) {
74
- throw new Error("Navigation entries do not support Vite glob entries");
75
- }
76
- if (
77
- ts.isCallExpression(node) &&
78
- (node.expression.kind === ts.SyntaxKind.ImportKeyword ||
79
- (ts.isPropertyAccessExpression(node.expression) &&
80
- ["docsLazy", "docLazy"].includes(node.expression.name.text)))
81
- ) {
82
- throw new Error(
83
- "Navigation entries currently require synchronous Fumadocs collections; leave docs.async disabled"
84
- );
85
- }
86
- ts.forEachChild(node, inspect);
87
- }
88
- inspect(file);
89
- for (const statement of file.statements) {
90
- if (
91
- !(
92
- ts.isImportDeclaration(statement) &&
93
- ts.isStringLiteral(statement.moduleSpecifier)
94
- )
95
- ) {
96
- continue;
97
- }
98
- const specifier = statement.moduleSpecifier;
99
- const separator = specifier.text.indexOf("?");
100
- const pathname =
101
- separator < 0 ? specifier.text : specifier.text.slice(0, separator);
102
- if (!MDX_EXTENSION.test(pathname)) {
103
- if (
104
- !(
105
- statement.importClause?.isTypeOnly ||
106
- META_EXTENSION.test(pathname) ||
107
- pathname === "fumadocs-mdx/runtime/server"
108
- )
109
- ) {
110
- throw new Error(`Unsupported navigation runtime import: ${pathname}`);
111
- }
112
- continue;
113
- }
114
- const query = new URLSearchParams(
115
- separator < 0 ? "" : specifier.text.slice(separator + 1)
116
- );
117
- if (!query.has("collection")) {
118
- throw new Error(
119
- "Navigation MDX imports must identify a Fumadocs collection"
120
- );
121
- }
122
- query.delete("geistdocs-data");
123
- query.set("only", "frontmatter");
124
- query.set("geistdocs-navigation", "1");
125
- edits.push({
126
- start: specifier.getStart(file),
127
- end: specifier.end,
128
- value: JSON.stringify(`${pathname}?${query}`),
129
- });
130
- }
131
- let code = serverCode;
132
- for (const edit of edits.reverse()) {
133
- code = code.slice(0, edit.start) + edit.value + code.slice(edit.end);
134
- }
135
- return { code, imports: edits.length };
136
- }