fumadocs-mdx 11.7.4 → 11.8.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 (44) hide show
  1. package/dist/{chunk-OWZSTKKX.js → chunk-6Y5JDZHD.js} +8 -1
  2. package/dist/chunk-7JFPDRW7.js +42 -0
  3. package/dist/chunk-GBMFGEC7.js +57 -0
  4. package/dist/{chunk-ZOWJF3OH.js → chunk-GX3THK2Q.js} +25 -20
  5. package/dist/{chunk-2CSSQTP6.js → chunk-GYWPPGFD.js} +9 -1
  6. package/dist/{chunk-PQCNPAD3.js → chunk-IGXZS2W6.js} +10 -7
  7. package/dist/chunk-UCY7OBZG.js +12 -0
  8. package/dist/{chunk-KVWX6THC.js → chunk-VWJKRQZR.js} +2 -2
  9. package/dist/{chunk-JFNBRKRV.js → chunk-XVL4ZQFK.js} +12 -6
  10. package/dist/{chunk-4CGSOZUZ.js → chunk-XZR5QXVY.js} +32 -2
  11. package/dist/config/index.cjs +21 -11
  12. package/dist/config/index.d.cts +2 -2
  13. package/dist/config/index.d.ts +2 -2
  14. package/dist/config/index.js +9 -37
  15. package/dist/config/zod-3.cjs +371 -0
  16. package/dist/config/zod-3.d.cts +53 -0
  17. package/dist/config/zod-3.d.ts +53 -0
  18. package/dist/config/zod-3.js +40 -0
  19. package/dist/{define-E6TRBwBQ.d.cts → define-DnJzAZrj.d.cts} +3 -2
  20. package/dist/{define-E6TRBwBQ.d.ts → define-DnJzAZrj.d.ts} +3 -2
  21. package/dist/index.d.cts +3 -3
  22. package/dist/index.d.ts +3 -3
  23. package/dist/loader-mdx.cjs +83 -50
  24. package/dist/loader-mdx.js +10 -10
  25. package/dist/{mdx-options-UDV5WEFU.js → mdx-options-3NB74EMB.js} +1 -1
  26. package/dist/next/index.cjs +63 -29
  27. package/dist/next/index.js +7 -9
  28. package/dist/runtime/async.cjs +167 -128
  29. package/dist/runtime/async.d.cts +3 -3
  30. package/dist/runtime/async.d.ts +3 -3
  31. package/dist/runtime/async.js +30 -46
  32. package/dist/runtime/vite.cjs +49 -41
  33. package/dist/runtime/vite.d.cts +26 -18
  34. package/dist/runtime/vite.d.ts +26 -18
  35. package/dist/runtime/vite.js +49 -41
  36. package/dist/{types-Lh_-Uuix.d.cts → types-B2ozVm_9.d.ts} +11 -5
  37. package/dist/{types-DiL328cG.d.ts → types-BukvTPdG.d.cts} +11 -5
  38. package/dist/vite/index.cjs +125 -99
  39. package/dist/vite/index.d.cts +6 -1
  40. package/dist/vite/index.d.ts +6 -1
  41. package/dist/vite/index.js +54 -38
  42. package/package.json +17 -12
  43. package/dist/chunk-2K55VKP6.js +0 -49
  44. package/dist/chunk-VUEZTR2H.js +0 -26
@@ -102,6 +102,7 @@ function getDefaultMDXOptions({
102
102
  remarkStructureOptions,
103
103
  remarkCodeTabOptions,
104
104
  remarkNpmOptions,
105
+ _withoutBundler = false,
105
106
  ...mdxOptions
106
107
  }) {
107
108
  const mdxExports = [
@@ -120,7 +121,13 @@ function getDefaultMDXOptions({
120
121
  ...remarkHeadingOptions
121
122
  }
122
123
  ],
123
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
124
+ remarkImageOptions !== false && [
125
+ plugins.remarkImage,
126
+ {
127
+ ...remarkImageOptions,
128
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
129
+ }
130
+ ],
124
131
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
125
132
  plugins.remarkCodeTab,
126
133
  remarkCodeTabOptions
@@ -145,6 +152,7 @@ function getDefaultMDXOptions({
145
152
  );
146
153
  return {
147
154
  ...mdxOptions,
155
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
148
156
  remarkPlugins,
149
157
  rehypePlugins
150
158
  };
@@ -165,12 +173,87 @@ __export(async_exports, {
165
173
  buildConfig: () => buildConfig
166
174
  });
167
175
  module.exports = __toCommonJS(async_exports);
168
- var import_mdx_remote = require("@fumadocs/mdx-remote");
176
+
177
+ // src/runtime/index.ts
178
+ var import_node_fs = __toESM(require("fs"), 1);
179
+ var cache = /* @__PURE__ */ new Map();
180
+ var _runtime = {
181
+ doc(files) {
182
+ return files.map((file) => {
183
+ const { default: body, frontmatter, ...exports2 } = file.data;
184
+ return {
185
+ body,
186
+ ...exports2,
187
+ ...frontmatter,
188
+ _file: file.info,
189
+ _exports: file.data,
190
+ get content() {
191
+ const path2 = this._file.absolutePath;
192
+ const cached = cache.get(path2);
193
+ if (cached) return cached;
194
+ const content = import_node_fs.default.readFileSync(path2).toString();
195
+ cache.set(path2, content);
196
+ return content;
197
+ }
198
+ };
199
+ });
200
+ },
201
+ meta(files) {
202
+ return files.map((file) => {
203
+ return {
204
+ ...file.data,
205
+ _file: file.info
206
+ };
207
+ });
208
+ },
209
+ docs(docs, metas) {
210
+ const parsedDocs = this.doc(docs);
211
+ const parsedMetas = this.meta(metas);
212
+ return {
213
+ docs: parsedDocs,
214
+ meta: parsedMetas,
215
+ toFumadocsSource() {
216
+ return createMDXSource(parsedDocs, parsedMetas);
217
+ }
218
+ };
219
+ }
220
+ };
221
+ function createMDXSource(docs, meta = []) {
222
+ return {
223
+ files: () => resolveFiles({
224
+ docs,
225
+ meta
226
+ })
227
+ };
228
+ }
229
+ function resolveFiles({ docs, meta }) {
230
+ const outputs = [];
231
+ for (const entry of docs) {
232
+ outputs.push({
233
+ type: "page",
234
+ absolutePath: entry._file.absolutePath,
235
+ path: entry._file.path,
236
+ data: entry
237
+ });
238
+ }
239
+ for (const entry of meta) {
240
+ outputs.push({
241
+ type: "meta",
242
+ absolutePath: entry._file.absolutePath,
243
+ path: entry._file.path,
244
+ data: entry
245
+ });
246
+ }
247
+ return outputs;
248
+ }
249
+
250
+ // src/utils/build-mdx.ts
251
+ var import_mdx = require("@mdx-js/mdx");
169
252
 
170
253
  // src/mdx-plugins/remark-include.ts
171
254
  var import_unist_util_visit = require("unist-util-visit");
172
255
  var path = __toESM(require("path"), 1);
173
- var fs = __toESM(require("fs/promises"), 1);
256
+ var fs2 = __toESM(require("fs/promises"), 1);
174
257
 
175
258
  // src/utils/fuma-matter.ts
176
259
  var import_js_yaml = require("js-yaml");
@@ -181,9 +264,9 @@ function fumaMatter(input) {
181
264
  if (!match) {
182
265
  return output;
183
266
  }
184
- output.matter = match[1];
267
+ output.matter = match[0];
185
268
  output.content = input.slice(match[0].length);
186
- const loaded = (0, import_js_yaml.load)(output.matter);
269
+ const loaded = (0, import_js_yaml.load)(match[1]);
187
270
  output.data = loaded ?? {};
188
271
  return output;
189
272
  }
@@ -217,7 +300,7 @@ function extractSection(root, section) {
217
300
  }
218
301
  function remarkInclude() {
219
302
  const TagName = "include";
220
- async function update(tree, directory, processor, compiler) {
303
+ async function update(tree, directory, data) {
221
304
  const queue = [];
222
305
  (0, import_unist_util_visit.visit)(
223
306
  tree,
@@ -244,8 +327,8 @@ function remarkInclude() {
244
327
  );
245
328
  const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
246
329
  queue.push(
247
- fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
248
- compiler?.addDependency(targetPath);
330
+ fs2.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
331
+ data._compiler?.addDependency(targetPath);
249
332
  if (asCode) {
250
333
  const lang = params.lang ?? path.extname(file).slice(1);
251
334
  Object.assign(node, {
@@ -257,6 +340,9 @@ function remarkInclude() {
257
340
  });
258
341
  return;
259
342
  }
343
+ const processor = data._processor ? data._processor.getProcessor(
344
+ targetPath.endsWith(".md") ? "md" : "mdx"
345
+ ) : this;
260
346
  let parsed = processor.parse(fumaMatter(content).content);
261
347
  if (section) {
262
348
  const extracted = extractSection(parsed, section);
@@ -266,11 +352,11 @@ function remarkInclude() {
266
352
  );
267
353
  parsed = extracted;
268
354
  }
269
- await update(
355
+ await update.call(
356
+ processor,
270
357
  parsed,
271
358
  path.dirname(targetPath),
272
- processor,
273
- compiler
359
+ data
274
360
  );
275
361
  Object.assign(
276
362
  parent && parent.type === "paragraph" ? parent : node,
@@ -290,86 +376,48 @@ ${e instanceof Error ? e.message : String(e)}`,
290
376
  await Promise.all(queue);
291
377
  }
292
378
  return async (tree, file) => {
293
- await update(tree, path.dirname(file.path), this, file.data._compiler);
379
+ await update.call(this, tree, path.dirname(file.path), file.data);
294
380
  };
295
381
  }
296
382
 
297
- // src/runtime/async.ts
298
- var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
299
-
300
- // src/runtime/index.ts
301
- var import_node_fs = __toESM(require("fs"), 1);
302
- var cache = /* @__PURE__ */ new Map();
303
- var _runtime = {
304
- doc(files) {
305
- return files.map((file) => {
306
- const { default: body, frontmatter, ...exports2 } = file.data;
307
- return {
308
- body,
309
- ...exports2,
310
- ...frontmatter,
311
- _file: file.info,
312
- _exports: file.data,
313
- get content() {
314
- const path2 = this._file.absolutePath;
315
- const cached = cache.get(path2);
316
- if (cached) return cached;
317
- const content = import_node_fs.default.readFileSync(path2).toString();
318
- cache.set(path2, content);
319
- return content;
320
- }
321
- };
322
- });
323
- },
324
- meta(files) {
325
- return files.map((file) => {
326
- return {
327
- ...file.data,
328
- _file: file.info
329
- };
330
- });
331
- },
332
- docs(docs, metas) {
333
- const parsedDocs = this.doc(docs);
334
- const parsedMetas = this.meta(metas);
335
- return {
336
- docs: parsedDocs,
337
- meta: parsedMetas,
338
- toFumadocsSource() {
339
- return createMDXSource(parsedDocs, parsedMetas);
340
- }
341
- };
342
- }
343
- };
344
- function createMDXSource(docs, meta = []) {
345
- return {
346
- files: () => resolveFiles({
347
- docs,
348
- meta
349
- })
350
- };
351
- }
352
- function resolveFiles({ docs, meta }) {
353
- const outputs = [];
354
- for (const entry of docs) {
355
- outputs.push({
356
- type: "page",
357
- absolutePath: entry._file.absolutePath,
358
- path: entry._file.path,
359
- data: entry
360
- });
361
- }
362
- for (const entry of meta) {
363
- outputs.push({
364
- type: "meta",
365
- absolutePath: entry._file.absolutePath,
366
- path: entry._file.path,
367
- data: entry
368
- });
383
+ // src/utils/build-mdx.ts
384
+ var cache2 = /* @__PURE__ */ new Map();
385
+ async function buildMDX(cacheKey, source, options) {
386
+ const { filePath, frontmatter, data, _compiler, ...rest } = options;
387
+ function getProcessor(format) {
388
+ const key = `${cacheKey}:${format}`;
389
+ let processor = cache2.get(key);
390
+ if (!processor) {
391
+ processor = (0, import_mdx.createProcessor)({
392
+ outputFormat: "program",
393
+ ...rest,
394
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
395
+ format
396
+ });
397
+ cache2.set(key, processor);
398
+ }
399
+ return processor;
369
400
  }
370
- return outputs;
401
+ return getProcessor(
402
+ options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
403
+ ).process({
404
+ value: source,
405
+ path: filePath,
406
+ data: {
407
+ ...data,
408
+ frontmatter,
409
+ _compiler,
410
+ _processor: {
411
+ getProcessor
412
+ }
413
+ }
414
+ });
371
415
  }
372
416
 
417
+ // src/runtime/async.ts
418
+ var import_client = require("@fumadocs/mdx-remote/client");
419
+ var import_node_url = require("url");
420
+
373
421
  // src/config/build.ts
374
422
  function buildConfig(config) {
375
423
  const collections = /* @__PURE__ */ new Map();
@@ -396,75 +444,66 @@ function buildConfig(config) {
396
444
  `Unknown export "${k}", you can only export collections from source configuration file.`
397
445
  );
398
446
  }
399
- let cachedMdxOptions;
447
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
400
448
  return {
401
449
  global: globalConfig,
402
450
  collections,
403
- async getDefaultMDXOptions() {
404
- if (cachedMdxOptions) return cachedMdxOptions;
451
+ async getDefaultMDXOptions(mode = "default") {
452
+ const cached = mdxOptionsCache.get(mode);
453
+ if (cached) return cached;
405
454
  const input = this.global.mdxOptions;
406
455
  async function uncached() {
407
456
  const options = typeof input === "function" ? await input() : input;
408
457
  const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
409
458
  if (options?.preset === "minimal") return options;
410
- return getDefaultMDXOptions2(options ?? {});
459
+ return getDefaultMDXOptions2({
460
+ ...options,
461
+ _withoutBundler: mode === "remote"
462
+ });
411
463
  }
412
- return cachedMdxOptions = uncached();
464
+ const result = uncached();
465
+ mdxOptionsCache.set(mode, result);
466
+ return result;
413
467
  }
414
468
  };
415
469
  }
416
470
 
417
471
  // src/runtime/async.ts
418
- async function initCompiler(config, collection) {
472
+ async function getOptions(config, collection) {
419
473
  const col = config.collections.get(collection);
420
- switch (col?.type) {
421
- case "doc":
422
- if (col.mdxOptions)
423
- return (0, import_mdx_remote.createCompiler)({
424
- preset: "minimal",
425
- ...col.mdxOptions
426
- });
427
- break;
428
- case "docs":
429
- if (col.docs.mdxOptions)
430
- return (0, import_mdx_remote.createCompiler)({
431
- preset: "minimal",
432
- ...col.docs.mdxOptions
433
- });
434
- break;
435
- }
436
- let defaultMdxOptions = config.global?.mdxOptions;
437
- if (typeof defaultMdxOptions === "function")
438
- defaultMdxOptions = await defaultMdxOptions();
439
- if (defaultMdxOptions?.preset === "minimal") {
440
- return (0, import_mdx_remote.createCompiler)(defaultMdxOptions);
441
- }
442
- const remarkPlugins = defaultMdxOptions?.remarkPlugins ?? [];
443
- return (0, import_mdx_remote.createCompiler)({
444
- ...defaultMdxOptions,
445
- remarkPlugins: (v) => typeof remarkPlugins === "function" ? [remarkInclude, ...remarkPlugins(v), import_mdx_plugins.remarkStructure] : [remarkInclude, ...v, ...remarkPlugins, import_mdx_plugins.remarkStructure]
446
- });
474
+ if (col?.type === "doc" && col.mdxOptions) return col.mdxOptions;
475
+ if (col?.type === "docs" && col.docs.mdxOptions) return col.docs.mdxOptions;
476
+ return config.getDefaultMDXOptions("remote");
447
477
  }
448
478
  var _runtimeAsync = {
449
479
  doc(files, collection, config) {
450
- const init = initCompiler(config, collection);
480
+ const initMdxOptions = getOptions(config, collection);
451
481
  return files.map(({ info: file, data, content, lastModified }) => {
452
482
  return {
453
483
  ...data,
454
484
  _file: file,
455
- content,
485
+ get content() {
486
+ return `${content.matter}${content.body}`;
487
+ },
456
488
  async load() {
457
- const compiler = await init;
458
- const out = await compiler.compile({
459
- source: content,
489
+ const mdxOptions = await initMdxOptions;
490
+ const out = await buildMDX(collection, content.body, {
491
+ ...mdxOptions,
492
+ development: false,
493
+ frontmatter: data,
494
+ data: {
495
+ lastModified
496
+ },
460
497
  filePath: file.absolutePath
461
498
  });
499
+ const { default: body, ...rest } = await (0, import_client.executeMdx)(String(out), {
500
+ baseUrl: (0, import_node_url.pathToFileURL)(file.absolutePath)
501
+ });
462
502
  return {
463
- body: out.body,
464
- toc: out.toc,
465
- lastModified,
466
- structuredData: out.vfile.data.structuredData,
467
- _exports: out.exports ?? {}
503
+ structuredData: out.data.structuredData,
504
+ body,
505
+ ...rest,
506
+ lastModified
468
507
  };
469
508
  }
470
509
  };
@@ -1,11 +1,11 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-Lh_-Uuix.cjs';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-BukvTPdG.cjs';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-E6TRBwBQ.cjs';
5
- import 'zod';
4
+ import '../define-DnJzAZrj.cjs';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import '@mdx-js/mdx';
8
7
  import 'unified';
8
+ import 'zod';
9
9
  import 'react';
10
10
  import 'mdx/types';
11
11
  import 'fumadocs-core/server';
@@ -1,11 +1,11 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-DiL328cG.js';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-B2ozVm_9.js';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-E6TRBwBQ.js';
5
- import 'zod';
4
+ import '../define-DnJzAZrj.js';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import '@mdx-js/mdx';
8
7
  import 'unified';
8
+ import 'zod';
9
9
  import 'react';
10
10
  import 'mdx/types';
11
11
  import 'fumadocs-core/server';
@@ -3,68 +3,52 @@ import {
3
3
  createMDXSource
4
4
  } from "../chunk-NUDEC6C5.js";
5
5
  import {
6
- remarkInclude
7
- } from "../chunk-PQCNPAD3.js";
6
+ buildMDX
7
+ } from "../chunk-7JFPDRW7.js";
8
+ import "../chunk-IGXZS2W6.js";
8
9
  import {
9
10
  buildConfig
10
- } from "../chunk-JFNBRKRV.js";
11
- import "../chunk-KVWX6THC.js";
11
+ } from "../chunk-XVL4ZQFK.js";
12
+ import "../chunk-VWJKRQZR.js";
12
13
 
13
14
  // src/runtime/async.ts
14
- import { createCompiler } from "@fumadocs/mdx-remote";
15
- import {
16
- remarkStructure
17
- } from "fumadocs-core/mdx-plugins";
18
- async function initCompiler(config, collection) {
15
+ import { executeMdx } from "@fumadocs/mdx-remote/client";
16
+ import { pathToFileURL } from "url";
17
+ async function getOptions(config, collection) {
19
18
  const col = config.collections.get(collection);
20
- switch (col?.type) {
21
- case "doc":
22
- if (col.mdxOptions)
23
- return createCompiler({
24
- preset: "minimal",
25
- ...col.mdxOptions
26
- });
27
- break;
28
- case "docs":
29
- if (col.docs.mdxOptions)
30
- return createCompiler({
31
- preset: "minimal",
32
- ...col.docs.mdxOptions
33
- });
34
- break;
35
- }
36
- let defaultMdxOptions = config.global?.mdxOptions;
37
- if (typeof defaultMdxOptions === "function")
38
- defaultMdxOptions = await defaultMdxOptions();
39
- if (defaultMdxOptions?.preset === "minimal") {
40
- return createCompiler(defaultMdxOptions);
41
- }
42
- const remarkPlugins = defaultMdxOptions?.remarkPlugins ?? [];
43
- return createCompiler({
44
- ...defaultMdxOptions,
45
- remarkPlugins: (v) => typeof remarkPlugins === "function" ? [remarkInclude, ...remarkPlugins(v), remarkStructure] : [remarkInclude, ...v, ...remarkPlugins, remarkStructure]
46
- });
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");
47
22
  }
48
23
  var _runtimeAsync = {
49
24
  doc(files, collection, config) {
50
- const init = initCompiler(config, collection);
25
+ const initMdxOptions = getOptions(config, collection);
51
26
  return files.map(({ info: file, data, content, lastModified }) => {
52
27
  return {
53
28
  ...data,
54
29
  _file: file,
55
- content,
30
+ get content() {
31
+ return `${content.matter}${content.body}`;
32
+ },
56
33
  async load() {
57
- const compiler = await init;
58
- const out = await compiler.compile({
59
- source: content,
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
+ },
60
42
  filePath: file.absolutePath
61
43
  });
44
+ const { default: body, ...rest } = await executeMdx(String(out), {
45
+ baseUrl: pathToFileURL(file.absolutePath)
46
+ });
62
47
  return {
63
- body: out.body,
64
- toc: out.toc,
65
- lastModified,
66
- structuredData: out.vfile.data.structuredData,
67
- _exports: out.exports ?? {}
48
+ structuredData: out.data.structuredData,
49
+ body,
50
+ ...rest,
51
+ lastModified
68
52
  };
69
53
  }
70
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
  }