fumadocs-mdx 11.10.1 → 12.0.0

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 (61) hide show
  1. package/dist/bin.cjs +29 -139
  2. package/dist/bin.js +1 -1
  3. package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
  4. package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
  5. package/dist/bun/index.cjs +126 -108
  6. package/dist/bun/index.js +5 -5
  7. package/dist/chunk-3M4SHY6K.js +80 -0
  8. package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
  9. package/dist/{chunk-QJCCVMBJ.js → chunk-KGUBBRL6.js} +11 -13
  10. package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
  11. package/dist/{chunk-766EAFX6.js → chunk-POXTQZ4D.js} +1 -31
  12. package/dist/chunk-SWNOXPYJ.js +142 -0
  13. package/dist/{chunk-XXSKWWMB.js → chunk-TLD6JMT6.js} +1 -1
  14. package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
  15. package/dist/{chunk-QVZ7JH4H.js → chunk-YC25YEBF.js} +1 -1
  16. package/dist/chunk-ZLCSVXCD.js +10 -0
  17. package/dist/config/index.cjs +18 -97
  18. package/dist/config/index.d.cts +1 -1
  19. package/dist/config/index.d.ts +1 -1
  20. package/dist/config/index.js +48 -9
  21. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.cts} +18 -3
  22. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.ts} +18 -3
  23. package/dist/loader-mdx.cjs +127 -139
  24. package/dist/loader-mdx.js +6 -6
  25. package/dist/next/index.cjs +29 -139
  26. package/dist/next/index.js +16 -16
  27. package/dist/node/loader.cjs +131 -143
  28. package/dist/node/loader.js +6 -6
  29. package/dist/postinstall-U7VROOY7.js +9 -0
  30. package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
  31. package/dist/runtime/next/async.cjs +198 -150
  32. package/dist/runtime/next/async.d.cts +3 -3
  33. package/dist/runtime/next/async.d.ts +3 -3
  34. package/dist/runtime/next/async.js +50 -30
  35. package/dist/runtime/next/index.cjs +32 -21
  36. package/dist/runtime/next/index.d.cts +11 -7
  37. package/dist/runtime/next/index.d.ts +11 -7
  38. package/dist/runtime/next/index.js +2 -1
  39. package/dist/runtime/vite/browser.d.cts +2 -3
  40. package/dist/runtime/vite/browser.d.ts +2 -3
  41. package/dist/runtime/vite/server.cjs +67 -21
  42. package/dist/runtime/vite/server.d.cts +14 -28
  43. package/dist/runtime/vite/server.d.ts +14 -28
  44. package/dist/runtime/vite/server.js +61 -21
  45. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  46. package/dist/shared-CqgMnt9h.d.cts +70 -0
  47. package/dist/{types-DN9KrG7R.d.ts → types-DLIAvrgC.d.ts} +6 -32
  48. package/dist/{types-DT83Ijs6.d.cts → types-Dl8HLbm5.d.cts} +6 -32
  49. package/dist/vite/index.cjs +131 -143
  50. package/dist/vite/index.js +7 -7
  51. package/package.json +2 -6
  52. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  53. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  54. package/dist/chunk-GBMFGEC7.js +0 -57
  55. package/dist/chunk-QQWCBFFE.js +0 -40
  56. package/dist/chunk-SMSNZ6N5.js +0 -155
  57. package/dist/config/zod-3.cjs +0 -422
  58. package/dist/config/zod-3.d.cts +0 -53
  59. package/dist/config/zod-3.d.ts +0 -53
  60. package/dist/config/zod-3.js +0 -40
  61. package/dist/postinstall-XV4WSHZP.js +0 -9
@@ -30,86 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // src/mdx-plugins/remark-postprocess.ts
34
- function remarkPostprocess({
35
- injectExports
36
- }) {
37
- return (tree, file) => {
38
- let title;
39
- const urls = [];
40
- (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
41
- if (node.type === "heading" && node.depth === 1) {
42
- title = flattenNode2(node);
43
- }
44
- if (node.type !== "link") return;
45
- urls.push({
46
- href: node.url
47
- });
48
- return "skip";
49
- });
50
- if (title) {
51
- file.data.frontmatter ??= {};
52
- if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
53
- }
54
- file.data.extractedReferences = urls;
55
- for (const name of injectExports) {
56
- if (!(name in file.data)) continue;
57
- tree.children.unshift(getMdastExport(name, file.data[name]));
58
- }
59
- };
60
- }
61
- function flattenNode2(node) {
62
- if ("children" in node)
63
- return node.children.map((child) => flattenNode2(child)).join("");
64
- if ("value" in node) return node.value;
65
- return "";
66
- }
67
- function getMdastExport(name, value) {
68
- return {
69
- type: "mdxjsEsm",
70
- value: "",
71
- data: {
72
- estree: {
73
- type: "Program",
74
- sourceType: "module",
75
- body: [
76
- {
77
- type: "ExportNamedDeclaration",
78
- attributes: [],
79
- specifiers: [],
80
- source: null,
81
- declaration: {
82
- type: "VariableDeclaration",
83
- kind: "let",
84
- declarations: [
85
- {
86
- type: "VariableDeclarator",
87
- id: {
88
- type: "Identifier",
89
- name
90
- },
91
- init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
92
- }
93
- ]
94
- }
95
- }
96
- ]
97
- }
98
- }
99
- };
100
- }
101
- var import_unist_util_visit2, import_estree_util_value_to_estree;
102
- var init_remark_postprocess = __esm({
103
- "src/mdx-plugins/remark-postprocess.ts"() {
104
- "use strict";
105
- import_unist_util_visit2 = require("unist-util-visit");
106
- import_estree_util_value_to_estree = require("estree-util-value-to-estree");
107
- }
108
- });
109
-
110
- // src/utils/mdx-options.ts
111
- var mdx_options_exports = {};
112
- __export(mdx_options_exports, {
33
+ // src/mdx/preset.ts
34
+ var preset_exports = {};
35
+ __export(preset_exports, {
113
36
  getDefaultMDXOptions: () => getDefaultMDXOptions
114
37
  });
115
38
  function pluginOption(def, options = []) {
@@ -132,13 +55,6 @@ function getDefaultMDXOptions({
132
55
  _withoutBundler = false,
133
56
  ...mdxOptions
134
57
  }) {
135
- const mdxExports = [
136
- "structuredData",
137
- "extractedReferences",
138
- "frontmatter",
139
- "lastModified",
140
- ...valueToExport
141
- ];
142
58
  const remarkPlugins = pluginOption(
143
59
  (v) => [
144
60
  plugins.remarkGfm,
@@ -166,10 +82,15 @@ function getDefaultMDXOptions({
166
82
  plugins.remarkStructure,
167
83
  remarkStructureOptions
168
84
  ],
169
- [
170
- remarkPostprocess,
171
- { injectExports: mdxExports }
172
- ]
85
+ () => {
86
+ return (_, file) => {
87
+ file.data["mdx-export"] ??= [];
88
+ for (const name of valueToExport) {
89
+ if (name in file.data)
90
+ file.data["mdx-export"].push({ name, value: file.data[name] });
91
+ }
92
+ };
93
+ }
173
94
  ],
174
95
  mdxOptions.remarkPlugins
175
96
  );
@@ -189,11 +110,10 @@ function getDefaultMDXOptions({
189
110
  };
190
111
  }
191
112
  var plugins;
192
- var init_mdx_options = __esm({
193
- "src/utils/mdx-options.ts"() {
113
+ var init_preset = __esm({
114
+ "src/mdx/preset.ts"() {
194
115
  "use strict";
195
116
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
196
- init_remark_postprocess();
197
117
  }
198
118
  });
199
119
 
@@ -206,25 +126,36 @@ __export(async_exports, {
206
126
  module.exports = __toCommonJS(async_exports);
207
127
 
208
128
  // src/runtime/next/index.ts
209
- var import_node_fs = __toESM(require("fs"), 1);
210
- var cache = /* @__PURE__ */ new Map();
129
+ var fs = __toESM(require("fs/promises"), 1);
130
+
131
+ // src/runtime/shared.ts
132
+ function missingProcessedMarkdown() {
133
+ throw new Error(
134
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
135
+ );
136
+ }
137
+
138
+ // src/runtime/next/index.ts
211
139
  var _runtime = {
212
140
  doc(files) {
213
141
  return files.map((file) => {
214
- const { default: body, frontmatter, ...exports2 } = file.data;
142
+ const data = file.data;
143
+ const filePath = file.info.fullPath;
215
144
  return {
216
- body,
217
- ...exports2,
218
- ...frontmatter,
219
- _file: file.info,
220
- _exports: file.data,
221
- get content() {
222
- const path2 = this._file.absolutePath;
223
- const cached = cache.get(path2);
224
- if (cached) return cached;
225
- const content = import_node_fs.default.readFileSync(path2).toString();
226
- cache.set(path2, content);
227
- return content;
145
+ info: file.info,
146
+ _exports: data,
147
+ body: data.default,
148
+ lastModified: data.lastModified,
149
+ toc: data.toc,
150
+ structuredData: data.structuredData,
151
+ extractedReferences: data.extractedReferences,
152
+ ...data.frontmatter,
153
+ async getText(type) {
154
+ if (type === "raw") {
155
+ return (await fs.readFile(filePath)).toString();
156
+ }
157
+ if (typeof data._markdown !== "string") missingProcessedMarkdown();
158
+ return data._markdown;
228
159
  }
229
160
  };
230
161
  });
@@ -232,8 +163,8 @@ var _runtime = {
232
163
  meta(files) {
233
164
  return files.map((file) => {
234
165
  return {
235
- ...file.data,
236
- _file: file.info
166
+ info: file.info,
167
+ ...file.data
237
168
  };
238
169
  });
239
170
  },
@@ -262,26 +193,26 @@ function resolveFiles({ docs, meta }) {
262
193
  for (const entry of docs) {
263
194
  outputs.push({
264
195
  type: "page",
265
- absolutePath: entry._file.absolutePath,
266
- path: entry._file.path,
196
+ absolutePath: entry.info.fullPath,
197
+ path: entry.info.path,
267
198
  data: entry
268
199
  });
269
200
  }
270
201
  for (const entry of meta) {
271
202
  outputs.push({
272
203
  type: "meta",
273
- absolutePath: entry._file.absolutePath,
274
- path: entry._file.path,
204
+ absolutePath: entry.info.fullPath,
205
+ path: entry.info.path,
275
206
  data: entry
276
207
  });
277
208
  }
278
209
  return outputs;
279
210
  }
280
211
 
281
- // src/utils/build-mdx.ts
212
+ // src/mdx/build-mdx.ts
282
213
  var import_mdx = require("@mdx-js/mdx");
283
214
 
284
- // src/mdx-plugins/remark-include.ts
215
+ // src/mdx/remark-include.ts
285
216
  var import_unified = require("unified");
286
217
  var import_unist_util_visit = require("unist-util-visit");
287
218
  var path = __toESM(require("path"), 1);
@@ -303,7 +234,7 @@ function fumaMatter(input) {
303
234
  return output;
304
235
  }
305
236
 
306
- // src/mdx-plugins/remark-include.ts
237
+ // src/mdx/remark-include.ts
307
238
  var import_remark_parse = __toESM(require("remark-parse"), 1);
308
239
  var import_remark_mdx = __toESM(require("remark-mdx"), 1);
309
240
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
@@ -431,21 +362,121 @@ function getDefaultProcessor(format) {
431
362
  return mdProcessor.use(import_remark_mdx.default);
432
363
  }
433
364
 
434
- // src/utils/build-mdx.ts
435
- var cache2 = /* @__PURE__ */ new Map();
365
+ // src/mdx/remark-postprocess.ts
366
+ var import_unist_util_visit2 = require("unist-util-visit");
367
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
368
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
369
+ function remarkPostprocess({
370
+ includeProcessedMarkdown = false,
371
+ valueToExport = []
372
+ } = {}) {
373
+ return (tree, file) => {
374
+ let title;
375
+ const urls = [];
376
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
377
+ if (node.type === "heading" && node.depth === 1) {
378
+ title = flattenNode2(node);
379
+ }
380
+ if (node.type !== "link") return;
381
+ urls.push({
382
+ href: node.url
383
+ });
384
+ return "skip";
385
+ });
386
+ if (title) {
387
+ file.data.frontmatter ??= {};
388
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
389
+ }
390
+ file.data.extractedReferences = urls;
391
+ if (includeProcessedMarkdown) {
392
+ file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
393
+ ...this.data("settings"),
394
+ // @ts-expect-error - from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
395
+ extensions: this.data("toMarkdownExtensions") || []
396
+ });
397
+ }
398
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
399
+ tree.children.unshift(getMdastExport(name, value));
400
+ }
401
+ for (const name of valueToExport) {
402
+ if (!(name in file.data)) continue;
403
+ tree.children.unshift(getMdastExport(name, file.data[name]));
404
+ }
405
+ };
406
+ }
407
+ function getMdastExport(name, value) {
408
+ return {
409
+ type: "mdxjsEsm",
410
+ value: "",
411
+ data: {
412
+ estree: {
413
+ type: "Program",
414
+ sourceType: "module",
415
+ body: [
416
+ {
417
+ type: "ExportNamedDeclaration",
418
+ attributes: [],
419
+ specifiers: [],
420
+ source: null,
421
+ declaration: {
422
+ type: "VariableDeclaration",
423
+ kind: "let",
424
+ declarations: [
425
+ {
426
+ type: "VariableDeclarator",
427
+ id: {
428
+ type: "Identifier",
429
+ name
430
+ },
431
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
432
+ }
433
+ ]
434
+ }
435
+ }
436
+ ]
437
+ }
438
+ }
439
+ };
440
+ }
441
+ function flattenNode2(node) {
442
+ if ("children" in node)
443
+ return node.children.map((child) => flattenNode2(child)).join("");
444
+ if ("value" in node) return node.value;
445
+ return "";
446
+ }
447
+
448
+ // src/mdx/build-mdx.ts
449
+ var cache = /* @__PURE__ */ new Map();
436
450
  async function buildMDX(cacheKey, source, options) {
437
451
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
438
452
  function getProcessor(format) {
439
453
  const key = `${cacheKey}:${format}`;
440
- let processor = cache2.get(key);
454
+ let processor = cache.get(key);
441
455
  if (!processor) {
442
456
  processor = (0, import_mdx.createProcessor)({
443
457
  outputFormat: "program",
444
458
  ...rest,
445
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
459
+ remarkPlugins: [
460
+ remarkInclude,
461
+ ...rest.remarkPlugins ?? [],
462
+ [
463
+ remarkPostprocess,
464
+ {
465
+ ...options.postprocess,
466
+ valueToExport: [
467
+ ...options.postprocess?.valueToExport ?? [],
468
+ "structuredData",
469
+ "extractedReferences",
470
+ "frontmatter",
471
+ "lastModified",
472
+ "_markdown"
473
+ ]
474
+ }
475
+ ]
476
+ ],
446
477
  format
447
478
  });
448
- cache2.set(key, processor);
479
+ cache.set(key, processor);
449
480
  }
450
481
  return processor;
451
482
  }
@@ -503,7 +534,7 @@ function buildConfig(config) {
503
534
  const input = this.global.mdxOptions;
504
535
  async function uncached() {
505
536
  const options = typeof input === "function" ? await input() : input;
506
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
537
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
507
538
  if (options?.preset === "minimal") return options;
508
539
  return getDefaultMDXOptions2({
509
540
  ...options,
@@ -518,41 +549,58 @@ function buildConfig(config) {
518
549
  }
519
550
 
520
551
  // src/runtime/next/async.ts
521
- async function getOptions(config, collection) {
552
+ function getDocCollection(config, collection) {
522
553
  const col = config.collections.get(collection);
523
- if (col?.type === "doc" && col.mdxOptions) return col.mdxOptions;
524
- if (col?.type === "docs" && col.docs.mdxOptions) return col.docs.mdxOptions;
525
- return config.getDefaultMDXOptions("remote");
554
+ if (col?.type === "doc" && col.mdxOptions) return col;
555
+ if (col?.type === "docs" && col.docs.mdxOptions) return col.docs;
556
+ }
557
+ async function getOptions(config, collection) {
558
+ return collection?.mdxOptions ?? await config.getDefaultMDXOptions("remote");
526
559
  }
527
560
  var _runtimeAsync = {
528
- doc(files, collection, config) {
561
+ doc(files, collectionName, config) {
562
+ const collection = getDocCollection(config, collectionName);
529
563
  const initMdxOptions = getOptions(config, collection);
530
- return files.map(({ info: file, data, content, lastModified }) => {
564
+ return files.map(({ info, data, content, lastModified }) => {
565
+ let cachedResult;
566
+ async function compileAndLoad() {
567
+ if (cachedResult) return cachedResult;
568
+ const mdxOptions = await initMdxOptions;
569
+ const compiled = await buildMDX(collectionName, content.body, {
570
+ ...mdxOptions,
571
+ development: false,
572
+ frontmatter: data,
573
+ postprocess: collection?.postprocess,
574
+ data: {
575
+ lastModified
576
+ },
577
+ filePath: info.fullPath
578
+ });
579
+ const result = await (0, import_client.executeMdx)(String(compiled.value), {
580
+ baseUrl: (0, import_node_url.pathToFileURL)(info.fullPath)
581
+ });
582
+ return cachedResult = result;
583
+ }
531
584
  return {
532
585
  ...data,
533
- _file: file,
534
- get content() {
535
- return `${content.matter}${content.body}`;
586
+ info,
587
+ async getText(type) {
588
+ if (type === "raw") {
589
+ return `${content.matter}${content.body}`;
590
+ }
591
+ const out = await compileAndLoad();
592
+ if (typeof out._markdown !== "string") missingProcessedMarkdown();
593
+ return out._markdown;
536
594
  },
537
595
  async load() {
538
- const mdxOptions = await initMdxOptions;
539
- const out = await buildMDX(collection, content.body, {
540
- ...mdxOptions,
541
- development: false,
542
- frontmatter: data,
543
- data: {
544
- lastModified
545
- },
546
- filePath: file.absolutePath
547
- });
548
- const { default: body, ...rest } = await (0, import_client.executeMdx)(String(out), {
549
- baseUrl: (0, import_node_url.pathToFileURL)(file.absolutePath)
550
- });
596
+ const out = await compileAndLoad();
551
597
  return {
552
- structuredData: out.data.structuredData,
553
- body,
554
- ...rest,
555
- lastModified
598
+ _exports: out,
599
+ body: out.default,
600
+ lastModified,
601
+ toc: out.toc,
602
+ extractedReferences: out.extractedReferences,
603
+ structuredData: out.structuredData
556
604
  };
557
605
  }
558
606
  };
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../../types-DT83Ijs6.cjs';
1
+ import { L as LoadedConfig, c as RuntimeAsync } from '../../types-Dl8HLbm5.cjs';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../../define-BH4bnHQl.cjs';
4
+ import '../../define--6HQ1ehX.cjs';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../../build-mdx-DnC1jKvn.cjs';
9
+ import '../../shared-CqgMnt9h.cjs';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../../types-DN9KrG7R.js';
1
+ import { L as LoadedConfig, c as RuntimeAsync } from '../../types-DLIAvrgC.js';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../../define-BH4bnHQl.js';
4
+ import '../../define--6HQ1ehX.js';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../../build-mdx-DnC1jKvn.js';
9
+ import '../../shared-0QIuV0XZ.js';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -1,54 +1,74 @@
1
1
  import {
2
2
  _runtime,
3
3
  createMDXSource
4
- } from "../../chunk-UOOPSLFY.js";
4
+ } from "../../chunk-AUOOMFAI.js";
5
+ import {
6
+ missingProcessedMarkdown
7
+ } from "../../chunk-ZLCSVXCD.js";
5
8
  import {
6
9
  buildMDX
7
- } from "../../chunk-QQWCBFFE.js";
8
- import "../../chunk-SVTXMVLQ.js";
10
+ } from "../../chunk-SWNOXPYJ.js";
11
+ import "../../chunk-KTDVTBMH.js";
9
12
  import {
10
13
  buildConfig
11
- } from "../../chunk-QVZ7JH4H.js";
14
+ } from "../../chunk-YC25YEBF.js";
12
15
  import "../../chunk-VWJKRQZR.js";
13
16
 
14
17
  // src/runtime/next/async.ts
15
18
  import { executeMdx } from "@fumadocs/mdx-remote/client";
16
19
  import { pathToFileURL } from "url";
17
- async function getOptions(config, collection) {
20
+ function getDocCollection(config, collection) {
18
21
  const col = config.collections.get(collection);
19
- if (col?.type === "doc" && col.mdxOptions) return col.mdxOptions;
20
- if (col?.type === "docs" && col.docs.mdxOptions) return col.docs.mdxOptions;
21
- return config.getDefaultMDXOptions("remote");
22
+ if (col?.type === "doc" && col.mdxOptions) return col;
23
+ if (col?.type === "docs" && col.docs.mdxOptions) return col.docs;
24
+ }
25
+ async function getOptions(config, collection) {
26
+ return collection?.mdxOptions ?? await config.getDefaultMDXOptions("remote");
22
27
  }
23
28
  var _runtimeAsync = {
24
- doc(files, collection, config) {
29
+ doc(files, collectionName, config) {
30
+ const collection = getDocCollection(config, collectionName);
25
31
  const initMdxOptions = getOptions(config, collection);
26
- return files.map(({ info: file, data, content, lastModified }) => {
32
+ return files.map(({ info, data, content, lastModified }) => {
33
+ let cachedResult;
34
+ async function compileAndLoad() {
35
+ if (cachedResult) return cachedResult;
36
+ const mdxOptions = await initMdxOptions;
37
+ const compiled = await buildMDX(collectionName, content.body, {
38
+ ...mdxOptions,
39
+ development: false,
40
+ frontmatter: data,
41
+ postprocess: collection?.postprocess,
42
+ data: {
43
+ lastModified
44
+ },
45
+ filePath: info.fullPath
46
+ });
47
+ const result = await executeMdx(String(compiled.value), {
48
+ baseUrl: pathToFileURL(info.fullPath)
49
+ });
50
+ return cachedResult = result;
51
+ }
27
52
  return {
28
53
  ...data,
29
- _file: file,
30
- get content() {
31
- return `${content.matter}${content.body}`;
54
+ info,
55
+ async getText(type) {
56
+ if (type === "raw") {
57
+ return `${content.matter}${content.body}`;
58
+ }
59
+ const out = await compileAndLoad();
60
+ if (typeof out._markdown !== "string") missingProcessedMarkdown();
61
+ return out._markdown;
32
62
  },
33
63
  async load() {
34
- const mdxOptions = await initMdxOptions;
35
- const out = await buildMDX(collection, content.body, {
36
- ...mdxOptions,
37
- development: false,
38
- frontmatter: data,
39
- data: {
40
- lastModified
41
- },
42
- filePath: file.absolutePath
43
- });
44
- const { default: body, ...rest } = await executeMdx(String(out), {
45
- baseUrl: pathToFileURL(file.absolutePath)
46
- });
64
+ const out = await compileAndLoad();
47
65
  return {
48
- structuredData: out.data.structuredData,
49
- body,
50
- ...rest,
51
- lastModified
66
+ _exports: out,
67
+ body: out.default,
68
+ lastModified,
69
+ toc: out.toc,
70
+ extractedReferences: out.extractedReferences,
71
+ structuredData: out.structuredData
52
72
  };
53
73
  }
54
74
  };
@@ -35,25 +35,36 @@ __export(next_exports, {
35
35
  resolveFiles: () => resolveFiles
36
36
  });
37
37
  module.exports = __toCommonJS(next_exports);
38
- var import_node_fs = __toESM(require("fs"), 1);
39
- var cache = /* @__PURE__ */ new Map();
38
+ var fs = __toESM(require("fs/promises"), 1);
39
+
40
+ // src/runtime/shared.ts
41
+ function missingProcessedMarkdown() {
42
+ throw new Error(
43
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
44
+ );
45
+ }
46
+
47
+ // src/runtime/next/index.ts
40
48
  var _runtime = {
41
49
  doc(files) {
42
50
  return files.map((file) => {
43
- const { default: body, frontmatter, ...exports2 } = file.data;
51
+ const data = file.data;
52
+ const filePath = file.info.fullPath;
44
53
  return {
45
- body,
46
- ...exports2,
47
- ...frontmatter,
48
- _file: file.info,
49
- _exports: file.data,
50
- get content() {
51
- const path = this._file.absolutePath;
52
- const cached = cache.get(path);
53
- if (cached) return cached;
54
- const content = import_node_fs.default.readFileSync(path).toString();
55
- cache.set(path, content);
56
- return content;
54
+ info: file.info,
55
+ _exports: data,
56
+ body: data.default,
57
+ lastModified: data.lastModified,
58
+ toc: data.toc,
59
+ structuredData: data.structuredData,
60
+ extractedReferences: data.extractedReferences,
61
+ ...data.frontmatter,
62
+ async getText(type) {
63
+ if (type === "raw") {
64
+ return (await fs.readFile(filePath)).toString();
65
+ }
66
+ if (typeof data._markdown !== "string") missingProcessedMarkdown();
67
+ return data._markdown;
57
68
  }
58
69
  };
59
70
  });
@@ -61,8 +72,8 @@ var _runtime = {
61
72
  meta(files) {
62
73
  return files.map((file) => {
63
74
  return {
64
- ...file.data,
65
- _file: file.info
75
+ info: file.info,
76
+ ...file.data
66
77
  };
67
78
  });
68
79
  },
@@ -91,16 +102,16 @@ function resolveFiles({ docs, meta }) {
91
102
  for (const entry of docs) {
92
103
  outputs.push({
93
104
  type: "page",
94
- absolutePath: entry._file.absolutePath,
95
- path: entry._file.path,
105
+ absolutePath: entry.info.fullPath,
106
+ path: entry.info.path,
96
107
  data: entry
97
108
  });
98
109
  }
99
110
  for (const entry of meta) {
100
111
  outputs.push({
101
112
  type: "meta",
102
- absolutePath: entry._file.absolutePath,
103
- path: entry._file.path,
113
+ absolutePath: entry.info.fullPath,
114
+ path: entry.info.path,
104
115
  data: entry
105
116
  });
106
117
  }