fumadocs-mdx 11.7.5 → 11.8.1

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 (35) hide show
  1. package/dist/build-mdx-DMe0r3s_.d.cts +44 -0
  2. package/dist/build-mdx-DMe0r3s_.d.ts +44 -0
  3. package/dist/{chunk-OWZSTKKX.js → chunk-6Y5JDZHD.js} +8 -1
  4. package/dist/{chunk-HWSF4OGZ.js → chunk-7JFPDRW7.js} +1 -1
  5. package/dist/{chunk-XZR5QXVY.js → chunk-BCOXAJMC.js} +1 -1
  6. package/dist/{chunk-GYWPPGFD.js → chunk-DJNS22RO.js} +18 -1
  7. package/dist/{chunk-3XN4P23K.js → chunk-IGXZS2W6.js} +1 -1
  8. package/dist/{chunk-XVL4ZQFK.js → chunk-S73DGUHI.js} +1 -1
  9. package/dist/{chunk-KVWX6THC.js → chunk-VWJKRQZR.js} +2 -2
  10. package/dist/config/index.cjs +22 -5
  11. package/dist/config/index.js +3 -3
  12. package/dist/config/zod-3.cjs +22 -5
  13. package/dist/config/zod-3.js +3 -3
  14. package/dist/index.d.cts +3 -2
  15. package/dist/index.d.ts +3 -2
  16. package/dist/loader-mdx.cjs +29 -5
  17. package/dist/loader-mdx.js +7 -7
  18. package/dist/{mdx-options-3NB74EMB.js → mdx-options-ILHLYYTL.js} +1 -1
  19. package/dist/next/index.cjs +36 -5
  20. package/dist/next/index.js +5 -5
  21. package/dist/runtime/async.cjs +35 -10
  22. package/dist/runtime/async.d.cts +3 -2
  23. package/dist/runtime/async.d.ts +3 -2
  24. package/dist/runtime/async.js +12 -11
  25. package/dist/runtime/vite.cjs +49 -41
  26. package/dist/runtime/vite.d.cts +27 -28
  27. package/dist/runtime/vite.d.ts +27 -28
  28. package/dist/runtime/vite.js +49 -41
  29. package/dist/{types-C-WXTx1W.d.cts → types-DvnkeVI3.d.cts} +12 -15
  30. package/dist/{types-CU9nn_je.d.ts → types-zBRxlyaM.d.ts} +12 -15
  31. package/dist/vite/index.cjs +101 -54
  32. package/dist/vite/index.d.cts +6 -1
  33. package/dist/vite/index.d.ts +6 -1
  34. package/dist/vite/index.js +51 -35
  35. package/package.json +11 -11
@@ -2,22 +2,22 @@ import {
2
2
  findConfigFile,
3
3
  getConfigHash,
4
4
  loadConfig
5
- } from "../chunk-XZR5QXVY.js";
5
+ } from "../chunk-BCOXAJMC.js";
6
6
  import {
7
7
  getGlobPatterns,
8
8
  getImportCode,
9
9
  isFileSupported,
10
10
  toImportPath
11
- } from "../chunk-OWZSTKKX.js";
11
+ } from "../chunk-6Y5JDZHD.js";
12
12
  import {
13
13
  ValidationError,
14
14
  getGitTimestamp,
15
15
  validate
16
16
  } from "../chunk-GX3THK2Q.js";
17
- import "../chunk-XVL4ZQFK.js";
17
+ import "../chunk-S73DGUHI.js";
18
18
  import {
19
19
  fumaMatter
20
- } from "../chunk-KVWX6THC.js";
20
+ } from "../chunk-VWJKRQZR.js";
21
21
 
22
22
  // src/map/index.ts
23
23
  import * as path2 from "path";
@@ -143,7 +143,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
143
143
  info: file,
144
144
  lastModified,
145
145
  data,
146
- content: parsed.content
146
+ content: { body: parsed.content, matter: parsed.matter }
147
147
  });
148
148
  });
149
149
  return Promise.all(entries2);
@@ -34,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  function remarkMdxExport({ values }) {
35
35
  return (tree, vfile) => {
36
36
  for (const name of values) {
37
- if (!(name in vfile.data)) return;
37
+ if (!(name in vfile.data)) continue;
38
38
  tree.children.unshift(getMdastExport(name, vfile.data[name]));
39
39
  }
40
40
  };
@@ -80,6 +80,27 @@ var init_remark_exports = __esm({
80
80
  }
81
81
  });
82
82
 
83
+ // src/mdx-plugins/remark-extract.ts
84
+ function remarkExtract() {
85
+ return (tree, file) => {
86
+ const urls = [];
87
+ (0, import_unist_util_visit2.visit)(tree, "link", (node) => {
88
+ urls.push({
89
+ href: node.url
90
+ });
91
+ return "skip";
92
+ });
93
+ file.data.extractedReferences = urls;
94
+ };
95
+ }
96
+ var import_unist_util_visit2;
97
+ var init_remark_extract = __esm({
98
+ "src/mdx-plugins/remark-extract.ts"() {
99
+ "use strict";
100
+ import_unist_util_visit2 = require("unist-util-visit");
101
+ }
102
+ });
103
+
83
104
  // src/utils/mdx-options.ts
84
105
  var mdx_options_exports = {};
85
106
  __export(mdx_options_exports, {
@@ -107,6 +128,7 @@ function getDefaultMDXOptions({
107
128
  }) {
108
129
  const mdxExports = [
109
130
  "structuredData",
131
+ "extractedReferences",
110
132
  "frontmatter",
111
133
  "lastModified",
112
134
  ...valueToExport
@@ -134,6 +156,7 @@ function getDefaultMDXOptions({
134
156
  ],
135
157
  "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
136
158
  ...v,
159
+ remarkExtract,
137
160
  remarkStructureOptions !== false && [
138
161
  plugins.remarkStructure,
139
162
  remarkStructureOptions
@@ -163,6 +186,7 @@ var init_mdx_options = __esm({
163
186
  "use strict";
164
187
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
165
188
  init_remark_exports();
189
+ init_remark_extract();
166
190
  }
167
191
  });
168
192
 
@@ -264,9 +288,9 @@ function fumaMatter(input) {
264
288
  if (!match) {
265
289
  return output;
266
290
  }
267
- output.matter = match[1];
291
+ output.matter = match[0];
268
292
  output.content = input.slice(match[0].length);
269
- const loaded = (0, import_js_yaml.load)(output.matter);
293
+ const loaded = (0, import_js_yaml.load)(match[1]);
270
294
  output.data = loaded ?? {};
271
295
  return output;
272
296
  }
@@ -482,10 +506,12 @@ var _runtimeAsync = {
482
506
  return {
483
507
  ...data,
484
508
  _file: file,
485
- content,
509
+ get content() {
510
+ return `${content.matter}${content.body}`;
511
+ },
486
512
  async load() {
487
513
  const mdxOptions = await initMdxOptions;
488
- const out = await buildMDX(collection, content, {
514
+ const out = await buildMDX(collection, content.body, {
489
515
  ...mdxOptions,
490
516
  development: false,
491
517
  frontmatter: data,
@@ -494,15 +520,14 @@ var _runtimeAsync = {
494
520
  },
495
521
  filePath: file.absolutePath
496
522
  });
497
- const executed = await (0, import_client.executeMdx)(String(out), {
523
+ const { default: body, ...rest } = await (0, import_client.executeMdx)(String(out), {
498
524
  baseUrl: (0, import_node_url.pathToFileURL)(file.absolutePath)
499
525
  });
500
526
  return {
501
- body: executed.default,
502
- toc: executed.toc,
503
- lastModified,
504
527
  structuredData: out.data.structuredData,
505
- _exports: executed
528
+ body,
529
+ ...rest,
530
+ lastModified
506
531
  };
507
532
  }
508
533
  };
@@ -1,4 +1,4 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-C-WXTx1W.cjs';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-DvnkeVI3.cjs';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
4
  import '../define-DnJzAZrj.cjs';
@@ -6,9 +6,10 @@ import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
+ import '../build-mdx-DMe0r3s_.cjs';
10
+ import 'fumadocs-core/server';
9
11
  import 'react';
10
12
  import 'mdx/types';
11
- import 'fumadocs-core/server';
12
13
 
13
14
  declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
14
15
 
@@ -1,4 +1,4 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-CU9nn_je.js';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-zBRxlyaM.js';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
4
  import '../define-DnJzAZrj.js';
@@ -6,9 +6,10 @@ import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
+ import '../build-mdx-DMe0r3s_.js';
10
+ import 'fumadocs-core/server';
9
11
  import 'react';
10
12
  import 'mdx/types';
11
- import 'fumadocs-core/server';
12
13
 
13
14
  declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
14
15
 
@@ -4,12 +4,12 @@ import {
4
4
  } from "../chunk-NUDEC6C5.js";
5
5
  import {
6
6
  buildMDX
7
- } from "../chunk-HWSF4OGZ.js";
8
- import "../chunk-3XN4P23K.js";
7
+ } from "../chunk-7JFPDRW7.js";
8
+ import "../chunk-IGXZS2W6.js";
9
9
  import {
10
10
  buildConfig
11
- } from "../chunk-XVL4ZQFK.js";
12
- import "../chunk-KVWX6THC.js";
11
+ } from "../chunk-S73DGUHI.js";
12
+ import "../chunk-VWJKRQZR.js";
13
13
 
14
14
  // src/runtime/async.ts
15
15
  import { executeMdx } from "@fumadocs/mdx-remote/client";
@@ -27,10 +27,12 @@ var _runtimeAsync = {
27
27
  return {
28
28
  ...data,
29
29
  _file: file,
30
- content,
30
+ get content() {
31
+ return `${content.matter}${content.body}`;
32
+ },
31
33
  async load() {
32
34
  const mdxOptions = await initMdxOptions;
33
- const out = await buildMDX(collection, content, {
35
+ const out = await buildMDX(collection, content.body, {
34
36
  ...mdxOptions,
35
37
  development: false,
36
38
  frontmatter: data,
@@ -39,15 +41,14 @@ var _runtimeAsync = {
39
41
  },
40
42
  filePath: file.absolutePath
41
43
  });
42
- const executed = await executeMdx(String(out), {
44
+ const { default: body, ...rest } = await executeMdx(String(out), {
43
45
  baseUrl: pathToFileURL(file.absolutePath)
44
46
  });
45
47
  return {
46
- body: executed.default,
47
- toc: executed.toc,
48
- lastModified,
49
48
  structuredData: out.data.structuredData,
50
- _exports: executed
49
+ body,
50
+ ...rest,
51
+ lastModified
51
52
  };
52
53
  }
53
54
  };
@@ -40,12 +40,22 @@ function fromConfig() {
40
40
  return {
41
41
  ...frontmatter,
42
42
  default: entry.default,
43
+ body: entry.default,
43
44
  toc,
44
45
  structuredData,
45
46
  lastModified,
46
47
  _exports: entry
47
48
  };
48
49
  }
50
+ function mapPageDataLazy(head, content) {
51
+ return {
52
+ ...head,
53
+ async load() {
54
+ const { default: body, ...rest } = await content();
55
+ return { body, ...rest };
56
+ }
57
+ };
58
+ }
49
59
  return {
50
60
  doc(_, glob) {
51
61
  return normalize(glob);
@@ -53,51 +63,49 @@ function fromConfig() {
53
63
  meta(_, glob) {
54
64
  return normalize(glob);
55
65
  },
56
- docs(_, { doc, meta }) {
57
- return {
58
- doc: normalize(doc),
59
- meta: normalize(meta)
60
- };
61
- },
62
- source(doc, meta) {
63
- const virtualFiles = [];
64
- for (const [file, content] of Object.entries(doc)) {
65
- virtualFiles.push({
66
- type: "page",
67
- path: file,
68
- data: mapPageData(content)
69
- });
70
- }
71
- for (const [file, content] of Object.entries(meta)) {
72
- virtualFiles.push({
73
- type: "meta",
74
- path: file,
75
- data: content
76
- });
77
- }
66
+ docLazy(_, head, body) {
78
67
  return {
79
- files: virtualFiles
68
+ head: normalize(head),
69
+ body: normalize(body)
80
70
  };
81
71
  },
82
72
  async sourceAsync(doc, meta) {
83
- const virtualFiles = [];
84
- for (const [file, content] of Object.entries(doc)) {
85
- virtualFiles.push({
86
- type: "page",
87
- path: file,
88
- data: mapPageData(await content())
89
- });
90
- }
91
- for (const [file, content] of Object.entries(meta)) {
92
- virtualFiles.push({
93
- type: "meta",
94
- path: file,
95
- data: await content()
96
- });
97
- }
98
- return {
99
- files: virtualFiles
100
- };
73
+ const virtualFiles = [
74
+ ...Object.entries(doc).map(async ([file, content]) => {
75
+ return {
76
+ type: "page",
77
+ path: file,
78
+ data: mapPageData(await content())
79
+ };
80
+ }),
81
+ ...Object.entries(meta).map(async ([file, content]) => {
82
+ return {
83
+ type: "meta",
84
+ path: file,
85
+ data: await content()
86
+ };
87
+ })
88
+ ];
89
+ return { files: await Promise.all(virtualFiles) };
90
+ },
91
+ async sourceLazy(doc, meta) {
92
+ const virtualFiles = [
93
+ ...Object.entries(doc.head).map(async ([file, frontmatter]) => {
94
+ return {
95
+ type: "page",
96
+ path: file,
97
+ data: mapPageDataLazy(await frontmatter(), doc.body[file])
98
+ };
99
+ }),
100
+ ...Object.entries(meta).map(async ([file, content]) => {
101
+ return {
102
+ type: "meta",
103
+ path: file,
104
+ data: await content()
105
+ };
106
+ })
107
+ ];
108
+ return { files: await Promise.all(virtualFiles) };
101
109
  }
102
110
  };
103
111
  }
@@ -1,47 +1,46 @@
1
- import { TableOfContents } from 'fumadocs-core/server';
2
1
  import { FC, ReactNode } from 'react';
3
2
  import { MDXProps } from 'mdx/types';
4
- import { StructuredData } from 'fumadocs-core/mdx-plugins';
5
- import { a as DocCollection, M as MetaCollection, b as DocsCollection } from '../define-DnJzAZrj.cjs';
3
+ import { a as DocCollection, b as DocsCollection, M as MetaCollection } from '../define-DnJzAZrj.cjs';
6
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
7
5
  import { PageData, MetaData, Source } from 'fumadocs-core/source';
6
+ import { C as CompiledMDXProperties } from '../build-mdx-DMe0r3s_.cjs';
7
+ import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
10
10
  import 'zod';
11
+ import 'fumadocs-core/server';
11
12
 
12
- interface CompiledMDXProperties<Frontmatter> {
13
- frontmatter: Frontmatter;
14
- structuredData: StructuredData;
15
- toc: TableOfContents;
16
- default: FC<MDXProps>;
13
+ type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
14
+ type Override<A, B> = Omit<A, keyof B> & B;
15
+ type MDXFileToPageData<Frontmatter> = Override<Omit<CompiledMDXProperties<Frontmatter>, 'frontmatter' | 'default'>, Frontmatter & {
17
16
  /**
18
- * Only available when `lastModifiedTime` is enabled on MDX loader
17
+ * @deprecated use `body` instead.
19
18
  */
20
- lastModified?: Date;
21
- }
22
- type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
23
- type MDXFileToPageData<Frontmatter> = Frontmatter & Omit<CompiledMDXProperties<Frontmatter>, 'frontmatter'> & {
19
+ default: FC<MDXProps>;
24
20
  _exports: Record<string, unknown>;
25
- };
26
- type AttachGlobValue<GlobValue, Attach> = GlobValue extends () => Promise<unknown> ? () => Promise<Attach> : Attach;
27
- declare function fromConfig<Config>(): {
28
- doc: <Name extends keyof Config, GlobValue>(name: Name, glob: Record<string, GlobValue>) => Config[Name] extends DocCollection<infer Schema> ? Record<string, AttachGlobValue<GlobValue, CompiledMDXFile<StandardSchemaV1.InferOutput<Schema>>>> : never;
29
- meta: <Name extends keyof Config, GlobValue>(name: Name, glob: Record<string, GlobValue>) => Config[Name] extends MetaCollection<infer Schema> ? AttachGlobValue<GlobValue, StandardSchemaV1.InferOutput<Schema>> : never;
30
- docs: <Name extends keyof Config, DocGlobValue, MetaGlobValue>(name: Name, options: {
31
- meta: Record<string, MetaGlobValue>;
32
- doc: Record<string, DocGlobValue>;
33
- }) => Config[Name] extends DocsCollection<infer DocSchema, infer MetaSchema> ? {
34
- doc: Record<string, AttachGlobValue<DocGlobValue, CompiledMDXFile<StandardSchemaV1.InferOutput<DocSchema>>>>;
35
- meta: Record<string, AttachGlobValue<MetaGlobValue, StandardSchemaV1.InferOutput<MetaSchema>>>;
36
- } : never;
37
- source: <DocOut extends PageData, MetaOut extends MetaData>(doc: Record<string, CompiledMDXFile<DocOut>>, meta: Record<string, MetaOut>) => Source<{
38
- pageData: MDXFileToPageData<DocOut>;
39
- metaData: MetaOut;
21
+ body: FC<MDXProps>;
22
+ }>;
23
+ type MDXFileToPageDataLazy<Frontmatter> = Override<Frontmatter, {
24
+ load: () => Promise<Omit<CompiledMDXFile<Frontmatter>, 'default'> & {
25
+ body: FC<MDXProps>;
40
26
  }>;
27
+ }>;
28
+ interface LazyDocMap<Frontmatter> {
29
+ head: Record<string, () => Promise<Frontmatter>>;
30
+ body: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
31
+ }
32
+ declare function fromConfig<Config>(): {
33
+ doc: <Name extends keyof Config>(name: Name, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? Record<string, () => Promise<CompiledMDXFile<StandardSchemaV1.InferOutput<Schema>>>> : never;
34
+ docLazy: <Name extends keyof Config>(name: Name, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
35
+ meta: <Name extends keyof Config>(name: Name, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? Record<string, () => Promise<StandardSchemaV1.InferOutput<Schema>>> : never;
41
36
  sourceAsync: <DocOut extends PageData, MetaOut extends MetaData>(doc: Record<string, () => Promise<CompiledMDXFile<DocOut>>>, meta: Record<string, () => Promise<MetaOut>>) => Promise<Source<{
42
37
  pageData: MDXFileToPageData<DocOut>;
43
38
  metaData: MetaOut;
44
39
  }>>;
40
+ sourceLazy: <DocOut extends PageData, MetaOut extends MetaData>(doc: LazyDocMap<DocOut>, meta: Record<string, () => Promise<MetaOut>>) => Promise<Source<{
41
+ pageData: MDXFileToPageDataLazy<DocOut>;
42
+ metaData: MetaOut;
43
+ }>>;
45
44
  };
46
45
  interface ClientLoaderOptions<Frontmatter, Props> {
47
46
  /**
@@ -1,47 +1,46 @@
1
- import { TableOfContents } from 'fumadocs-core/server';
2
1
  import { FC, ReactNode } from 'react';
3
2
  import { MDXProps } from 'mdx/types';
4
- import { StructuredData } from 'fumadocs-core/mdx-plugins';
5
- import { a as DocCollection, M as MetaCollection, b as DocsCollection } from '../define-DnJzAZrj.js';
3
+ import { a as DocCollection, b as DocsCollection, M as MetaCollection } from '../define-DnJzAZrj.js';
6
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
7
5
  import { PageData, MetaData, Source } from 'fumadocs-core/source';
6
+ import { C as CompiledMDXProperties } from '../build-mdx-DMe0r3s_.js';
7
+ import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
10
10
  import 'zod';
11
+ import 'fumadocs-core/server';
11
12
 
12
- interface CompiledMDXProperties<Frontmatter> {
13
- frontmatter: Frontmatter;
14
- structuredData: StructuredData;
15
- toc: TableOfContents;
16
- default: FC<MDXProps>;
13
+ type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
14
+ type Override<A, B> = Omit<A, keyof B> & B;
15
+ type MDXFileToPageData<Frontmatter> = Override<Omit<CompiledMDXProperties<Frontmatter>, 'frontmatter' | 'default'>, Frontmatter & {
17
16
  /**
18
- * Only available when `lastModifiedTime` is enabled on MDX loader
17
+ * @deprecated use `body` instead.
19
18
  */
20
- lastModified?: Date;
21
- }
22
- type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
23
- type MDXFileToPageData<Frontmatter> = Frontmatter & Omit<CompiledMDXProperties<Frontmatter>, 'frontmatter'> & {
19
+ default: FC<MDXProps>;
24
20
  _exports: Record<string, unknown>;
25
- };
26
- type AttachGlobValue<GlobValue, Attach> = GlobValue extends () => Promise<unknown> ? () => Promise<Attach> : Attach;
27
- declare function fromConfig<Config>(): {
28
- doc: <Name extends keyof Config, GlobValue>(name: Name, glob: Record<string, GlobValue>) => Config[Name] extends DocCollection<infer Schema> ? Record<string, AttachGlobValue<GlobValue, CompiledMDXFile<StandardSchemaV1.InferOutput<Schema>>>> : never;
29
- meta: <Name extends keyof Config, GlobValue>(name: Name, glob: Record<string, GlobValue>) => Config[Name] extends MetaCollection<infer Schema> ? AttachGlobValue<GlobValue, StandardSchemaV1.InferOutput<Schema>> : never;
30
- docs: <Name extends keyof Config, DocGlobValue, MetaGlobValue>(name: Name, options: {
31
- meta: Record<string, MetaGlobValue>;
32
- doc: Record<string, DocGlobValue>;
33
- }) => Config[Name] extends DocsCollection<infer DocSchema, infer MetaSchema> ? {
34
- doc: Record<string, AttachGlobValue<DocGlobValue, CompiledMDXFile<StandardSchemaV1.InferOutput<DocSchema>>>>;
35
- meta: Record<string, AttachGlobValue<MetaGlobValue, StandardSchemaV1.InferOutput<MetaSchema>>>;
36
- } : never;
37
- source: <DocOut extends PageData, MetaOut extends MetaData>(doc: Record<string, CompiledMDXFile<DocOut>>, meta: Record<string, MetaOut>) => Source<{
38
- pageData: MDXFileToPageData<DocOut>;
39
- metaData: MetaOut;
21
+ body: FC<MDXProps>;
22
+ }>;
23
+ type MDXFileToPageDataLazy<Frontmatter> = Override<Frontmatter, {
24
+ load: () => Promise<Omit<CompiledMDXFile<Frontmatter>, 'default'> & {
25
+ body: FC<MDXProps>;
40
26
  }>;
27
+ }>;
28
+ interface LazyDocMap<Frontmatter> {
29
+ head: Record<string, () => Promise<Frontmatter>>;
30
+ body: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
31
+ }
32
+ declare function fromConfig<Config>(): {
33
+ doc: <Name extends keyof Config>(name: Name, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? Record<string, () => Promise<CompiledMDXFile<StandardSchemaV1.InferOutput<Schema>>>> : never;
34
+ docLazy: <Name extends keyof Config>(name: Name, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
35
+ meta: <Name extends keyof Config>(name: Name, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? Record<string, () => Promise<StandardSchemaV1.InferOutput<Schema>>> : never;
41
36
  sourceAsync: <DocOut extends PageData, MetaOut extends MetaData>(doc: Record<string, () => Promise<CompiledMDXFile<DocOut>>>, meta: Record<string, () => Promise<MetaOut>>) => Promise<Source<{
42
37
  pageData: MDXFileToPageData<DocOut>;
43
38
  metaData: MetaOut;
44
39
  }>>;
40
+ sourceLazy: <DocOut extends PageData, MetaOut extends MetaData>(doc: LazyDocMap<DocOut>, meta: Record<string, () => Promise<MetaOut>>) => Promise<Source<{
41
+ pageData: MDXFileToPageDataLazy<DocOut>;
42
+ metaData: MetaOut;
43
+ }>>;
45
44
  };
46
45
  interface ClientLoaderOptions<Frontmatter, Props> {
47
46
  /**
@@ -14,12 +14,22 @@ function fromConfig() {
14
14
  return {
15
15
  ...frontmatter,
16
16
  default: entry.default,
17
+ body: entry.default,
17
18
  toc,
18
19
  structuredData,
19
20
  lastModified,
20
21
  _exports: entry
21
22
  };
22
23
  }
24
+ function mapPageDataLazy(head, content) {
25
+ return {
26
+ ...head,
27
+ async load() {
28
+ const { default: body, ...rest } = await content();
29
+ return { body, ...rest };
30
+ }
31
+ };
32
+ }
23
33
  return {
24
34
  doc(_, glob) {
25
35
  return normalize(glob);
@@ -27,51 +37,49 @@ function fromConfig() {
27
37
  meta(_, glob) {
28
38
  return normalize(glob);
29
39
  },
30
- docs(_, { doc, meta }) {
31
- return {
32
- doc: normalize(doc),
33
- meta: normalize(meta)
34
- };
35
- },
36
- source(doc, meta) {
37
- const virtualFiles = [];
38
- for (const [file, content] of Object.entries(doc)) {
39
- virtualFiles.push({
40
- type: "page",
41
- path: file,
42
- data: mapPageData(content)
43
- });
44
- }
45
- for (const [file, content] of Object.entries(meta)) {
46
- virtualFiles.push({
47
- type: "meta",
48
- path: file,
49
- data: content
50
- });
51
- }
40
+ docLazy(_, head, body) {
52
41
  return {
53
- files: virtualFiles
42
+ head: normalize(head),
43
+ body: normalize(body)
54
44
  };
55
45
  },
56
46
  async sourceAsync(doc, meta) {
57
- const virtualFiles = [];
58
- for (const [file, content] of Object.entries(doc)) {
59
- virtualFiles.push({
60
- type: "page",
61
- path: file,
62
- data: mapPageData(await content())
63
- });
64
- }
65
- for (const [file, content] of Object.entries(meta)) {
66
- virtualFiles.push({
67
- type: "meta",
68
- path: file,
69
- data: await content()
70
- });
71
- }
72
- return {
73
- files: virtualFiles
74
- };
47
+ const virtualFiles = [
48
+ ...Object.entries(doc).map(async ([file, content]) => {
49
+ return {
50
+ type: "page",
51
+ path: file,
52
+ data: mapPageData(await content())
53
+ };
54
+ }),
55
+ ...Object.entries(meta).map(async ([file, content]) => {
56
+ return {
57
+ type: "meta",
58
+ path: file,
59
+ data: await content()
60
+ };
61
+ })
62
+ ];
63
+ return { files: await Promise.all(virtualFiles) };
64
+ },
65
+ async sourceLazy(doc, meta) {
66
+ const virtualFiles = [
67
+ ...Object.entries(doc.head).map(async ([file, frontmatter]) => {
68
+ return {
69
+ type: "page",
70
+ path: file,
71
+ data: mapPageDataLazy(await frontmatter(), doc.body[file])
72
+ };
73
+ }),
74
+ ...Object.entries(meta).map(async ([file, content]) => {
75
+ return {
76
+ type: "meta",
77
+ path: file,
78
+ data: await content()
79
+ };
80
+ })
81
+ ];
82
+ return { files: await Promise.all(virtualFiles) };
75
83
  }
76
84
  };
77
85
  }
@@ -2,10 +2,7 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
3
  import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-DnJzAZrj.cjs';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { FC } from 'react';
6
- import { MDXProps } from 'mdx/types';
7
- import { StructuredData } from 'fumadocs-core/mdx-plugins';
8
- import { TableOfContents } from 'fumadocs-core/server';
5
+ import { C as CompiledMDXProperties } from './build-mdx-DMe0r3s_.cjs';
9
6
 
10
7
  interface LoadedConfig {
11
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
@@ -23,15 +20,8 @@ interface FileInfo {
23
20
  path: string;
24
21
  absolutePath: string;
25
22
  }
26
- interface MarkdownProps {
27
- body: FC<MDXProps>;
28
- structuredData: StructuredData;
29
- toc: TableOfContents;
30
- _exports: Record<string, unknown>;
31
- /**
32
- * Only available when `lastModifiedTime` is enabled on MDX loader
33
- */
34
- lastModified?: Date;
23
+ interface MarkdownProps extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
24
+ body: CompiledMDXProperties['default'];
35
25
  }
36
26
  interface RuntimeFile {
37
27
  info: FileInfo;
@@ -40,10 +30,17 @@ interface RuntimeFile {
40
30
  interface AsyncRuntimeFile {
41
31
  info: FileInfo;
42
32
  data: Record<string, unknown>;
43
- content: string;
33
+ content: {
34
+ matter: string;
35
+ body: string;
36
+ };
44
37
  lastModified?: Date;
45
38
  }
46
39
  type DocOut<Schema extends StandardSchemaV1> = Override<MarkdownProps & {
40
+ /**
41
+ * Other exports in the compiled Markdown/MDX file
42
+ */
43
+ _exports: Record<string, unknown>;
47
44
  /**
48
45
  * Read the original content of file from file system.
49
46
  */
@@ -65,7 +62,7 @@ interface Runtime {
65
62
  }
66
63
  type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
67
64
  content: string;
68
- load: () => Promise<MarkdownProps>;
65
+ load: () => Promise<MarkdownProps & Record<string, unknown>>;
69
66
  };
70
67
  interface RuntimeAsync {
71
68
  doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends DocCollection<infer Schema, true> ? AsyncDocOut<Schema>[] : never;