fumadocs-core 15.8.0 → 15.8.2

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.
@@ -1,54 +1,6 @@
1
- import { ReactNode } from 'react';
2
- import { R as Root, I as Item, F as Folder, S as Separator } from '../definitions-Q95-psoo.js';
1
+ import { I as Item, F as Folder, S as Separator, R as Root } from '../definitions-Q95-psoo.js';
3
2
  import { I18nConfig } from '../i18n/index.js';
4
-
5
- /**
6
- * In memory file system.
7
- */
8
- declare class FileSystem<File> {
9
- files: Map<string, File>;
10
- folders: Map<string, string[]>;
11
- constructor(inherit?: FileSystem<File>);
12
- read(path: string): File | undefined;
13
- /**
14
- * get the direct children of folder (in virtual file path)
15
- */
16
- readDir(path: string): string[] | undefined;
17
- write(path: string, file: File): void;
18
- delete(path: string): boolean;
19
- deleteDir(path: string): boolean;
20
- getFiles(): string[];
21
- makeDir(path: string): void;
22
- }
23
-
24
- interface LoadOptions {
25
- transformers?: Transformer[];
26
- buildFile: (file: VirtualFile) => MetaFile | PageFile;
27
- }
28
- type ContentStorage<Page extends PageData = PageData, Meta extends MetaData = MetaData> = FileSystem<MetaFile<Meta> | PageFile<Page>>;
29
- interface MetaFile<Data extends MetaData = MetaData> {
30
- path: string;
31
- absolutePath: string;
32
- format: 'meta';
33
- data: Data;
34
- }
35
- interface PageFile<Data extends PageData = PageData> {
36
- path: string;
37
- absolutePath: string;
38
- format: 'page';
39
- slugs: string[];
40
- data: Data;
41
- }
42
- type Transformer = (context: {
43
- storage: ContentStorage;
44
- options: LoadOptions;
45
- }) => void;
46
- /**
47
- * @returns a map of locale and its content storage.
48
- *
49
- * in the storage, locale codes are removed from file paths, hence the same file will have same file paths in every storage.
50
- */
51
- declare function loadFiles(files: VirtualFile[], options: LoadOptions, i18n: I18nConfig): Record<string, ContentStorage>;
3
+ import { ReactNode } from 'react';
52
4
 
53
5
  interface FileInfo {
54
6
  /**
@@ -85,10 +37,50 @@ interface FolderInfo {
85
37
  dirname: string;
86
38
  }
87
39
  declare function parseFilePath(path: string): FileInfo;
88
- /**
89
- * @deprecated use `dirname` and `basename` directly.
90
- */
91
- declare function parseFolderPath(path: string): FolderInfo;
40
+
41
+ type LoaderPlugins<Page extends PageData, Meta extends MetaData> = LoaderPlugin<Page, Meta>[];
42
+ interface LoaderPlugin<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
43
+ /**
44
+ * transform the storage after loading
45
+ */
46
+ transformStorage?: (context: {
47
+ storage: ContentStorage<Page, Meta>;
48
+ }) => void;
49
+ /**
50
+ * transform the generated page tree
51
+ */
52
+ transformPageTree?: PageTreeTransformer<Page, Meta>;
53
+ }
54
+ declare function buildPlugins<Page extends PageData, Meta extends MetaData>(plugins: LoaderPlugins<Page, Meta>): LoaderPlugin<Page, Meta>[];
55
+
56
+ interface LegacyLoaderOptions {
57
+ /**
58
+ * We recommend you to use `plugins` instead
59
+ */
60
+ transformers?: Transformer[];
61
+ }
62
+ interface LegacyPageTreeOptions<Page extends PageData, Meta extends MetaData> {
63
+ /**
64
+ * @deprecated use `plugins` instead
65
+ */
66
+ attachFile?: (node: Item, file?: PageFile<Page>) => Item;
67
+ /**
68
+ * @deprecated use `plugins` instead
69
+ */
70
+ attachFolder?: (node: Folder, folder: {
71
+ children: (PageFile<Page> | MetaFile<Meta>)[];
72
+ }, meta?: MetaFile<Meta>) => Folder;
73
+ /**
74
+ * @deprecated use `plugins` instead
75
+ */
76
+ attachSeparator?: (node: Separator) => Separator;
77
+ /**
78
+ * We recommend you to use `plugins` instead
79
+ */
80
+ transformers?: PageTreeTransformer<Page, Meta>[];
81
+ }
82
+
83
+ type IconResolver = (icon: string | undefined) => ReactNode;
92
84
 
93
85
  interface LoaderConfig {
94
86
  source: SourceConfig;
@@ -98,21 +90,23 @@ interface SourceConfig {
98
90
  pageData: PageData;
99
91
  metaData: MetaData;
100
92
  }
101
- interface LoaderOptions<T extends SourceConfig = SourceConfig, I18n extends I18nConfig | undefined = I18nConfig | undefined> {
93
+ type LoaderOptions<Config extends SourceConfig = SourceConfig, I18n extends I18nConfig | undefined = I18nConfig | undefined> = BaseLoaderOptions<NoInfer<Config>> & {
94
+ source: Source<Config> | Source<Config>[];
95
+ /**
96
+ * Configure i18n
97
+ */
98
+ i18n?: I18n;
99
+ };
100
+ interface BaseLoaderOptions<Config extends SourceConfig> extends LegacyLoaderOptions {
102
101
  baseUrl: string;
103
- icon?: NonNullable<BaseOptions['resolveIcon']>;
102
+ icon?: IconResolver;
104
103
  slugs?: (info: FileInfo) => string[];
105
104
  url?: UrlFn;
106
- source: Source<T> | Source<T>[];
107
- transformers?: Transformer[];
108
105
  /**
109
106
  * Additional options for page tree builder
110
107
  */
111
- pageTree?: Partial<BaseOptions<T['pageData'], T['metaData']>>;
112
- /**
113
- * Configure i18n
114
- */
115
- i18n?: I18n;
108
+ pageTree?: Partial<BaseOptions> & LegacyPageTreeOptions<Config['pageData'], Config['metaData']>;
109
+ plugins?: LoaderPlugins<Config['pageData'], Config['metaData']>;
116
110
  }
117
111
  interface Source<Config extends SourceConfig> {
118
112
  /**
@@ -183,13 +177,19 @@ interface LoaderOutput<Config extends LoaderConfig> {
183
177
  page: Page<Config['source']['pageData']>;
184
178
  hash?: string;
185
179
  } | undefined;
180
+ /**
181
+ * @internal
182
+ */
186
183
  _i18n?: I18nConfig;
187
184
  /**
188
- * Get list of pages from language
185
+ * Get a list of pages from specified language
189
186
  *
190
- * @param language - If empty, the default language will be used
187
+ * @param language - If empty, list pages from all languages.
191
188
  */
192
189
  getPages: (language?: string) => Page<Config['source']['pageData']>[];
190
+ /**
191
+ * get each language and its pages, empty if i18n is not enabled.
192
+ */
193
193
  getLanguages: () => LanguageEntry<Config['source']['pageData']>[];
194
194
  /**
195
195
  * Get page with slugs
@@ -237,53 +237,83 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
237
237
  */
238
238
  type UrlFn = (slugs: string[], locale?: string) => string;
239
239
 
240
- interface LegacyTransformerOptions<Page extends PageData, Meta extends MetaData> {
241
- /**
242
- * @deprecated use `transformers` instead
243
- */
244
- attachFile?: (node: Item, file?: PageFile<Page>) => Item;
245
- /**
246
- * @deprecated use `transformers` instead
247
- */
248
- attachFolder?: (node: Folder, folder: {
249
- children: (PageFile<Page> | MetaFile<Meta>)[];
250
- }, meta?: MetaFile<Meta>) => Folder;
240
+ /**
241
+ * In memory file system.
242
+ */
243
+ declare class FileSystem<File> {
244
+ files: Map<string, File>;
245
+ folders: Map<string, string[]>;
246
+ constructor(inherit?: FileSystem<File>);
247
+ read(path: string): File | undefined;
251
248
  /**
252
- * @deprecated use `transformers` instead
249
+ * get the direct children of folder (in virtual file path)
253
250
  */
254
- attachSeparator?: (node: Separator) => Separator;
251
+ readDir(path: string): string[] | undefined;
252
+ write(path: string, file: File): void;
253
+ delete(path: string): boolean;
254
+ deleteDir(path: string): boolean;
255
+ getFiles(): string[];
256
+ makeDir(path: string): void;
257
+ }
258
+
259
+ interface LoadOptions {
260
+ buildFile: (file: VirtualFile) => MetaFile | PageFile;
261
+ plugins?: LoaderPlugin[];
262
+ }
263
+ type ContentStorage<Page extends PageData = PageData, Meta extends MetaData = MetaData> = FileSystem<MetaFile<Meta> | PageFile<Page>>;
264
+ interface MetaFile<Data extends MetaData = MetaData> {
265
+ path: string;
266
+ absolutePath: string;
267
+ format: 'meta';
268
+ data: Data;
255
269
  }
270
+ interface PageFile<Data extends PageData = PageData> {
271
+ path: string;
272
+ absolutePath: string;
273
+ format: 'page';
274
+ slugs: string[];
275
+ data: Data;
276
+ }
277
+ type Transformer = (context: {
278
+ storage: ContentStorage;
279
+ }) => void;
280
+ /**
281
+ * @returns a map of locale and its content storage.
282
+ *
283
+ * in the storage, locale codes are removed from file paths, hence the same file will have same file paths in every storage.
284
+ */
285
+ declare function loadFiles(files: VirtualFile[], options: LoadOptions, i18n: I18nConfig): Record<string, ContentStorage>;
256
286
 
257
287
  interface PageTreeBuilderContext<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
258
288
  /**
259
289
  * @internal resolve paths without extensions
260
290
  */
261
291
  resolveName: (name: string, format: 'meta' | 'page') => string;
262
- options: BaseOptions<Page, Meta>;
292
+ options: BaseOptions;
263
293
  transformers: PageTreeTransformer<Page, Meta>[];
264
- builder: PageTreeBuilder<Page, Meta>;
294
+ builder: PageTreeBuilder;
265
295
  storage: ContentStorage<Page, Meta>;
266
296
  getUrl: UrlFn;
267
297
  storages?: Record<string, ContentStorage<Page, Meta>>;
268
298
  locale?: string;
269
299
  visitedPaths: Set<string>;
270
300
  }
271
- interface PageTreeTransformer<Page extends PageData = any, Meta extends MetaData = any> {
301
+ interface PageTreeTransformer<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
272
302
  name?: string;
273
303
  file?: (this: PageTreeBuilderContext<Page, Meta>, node: Item, filePath?: string) => Item;
274
304
  folder?: (this: PageTreeBuilderContext<Page, Meta>, node: Folder, folderPath: string, metaPath?: string) => Folder;
275
305
  separator?: (this: PageTreeBuilderContext<Page, Meta>, node: Separator) => Separator;
276
306
  root?: (this: PageTreeBuilderContext<Page, Meta>, node: Root) => Root;
277
307
  }
278
- interface BaseOptions<Page extends PageData = PageData, Meta extends MetaData = MetaData> extends LegacyTransformerOptions<Page, Meta> {
308
+ interface BaseOptions {
309
+ id?: string;
279
310
  /**
280
311
  * Remove references to the file path of original nodes (`$ref`)
281
312
  *
282
313
  * @defaultValue false
283
314
  */
284
315
  noRef?: boolean;
285
- transformers?: PageTreeTransformer<Page, Meta>[];
286
- resolveIcon?: (icon: string | undefined) => ReactNode | undefined;
316
+ plugins?: LoaderPlugin[];
287
317
  /**
288
318
  * generate fallback page tree
289
319
  *
@@ -291,19 +321,17 @@ interface BaseOptions<Page extends PageData = PageData, Meta extends MetaData =
291
321
  */
292
322
  generateFallback?: boolean;
293
323
  }
294
- interface PageTreeBuilder<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
295
- build: (options: BaseOptions<Page, Meta> & {
296
- id?: string;
297
- storage: ContentStorage<Page, Meta>;
324
+ interface PageTreeBuilder {
325
+ build: (options: BaseOptions & {
326
+ storage: ContentStorage;
298
327
  }) => Root;
299
328
  /**
300
329
  * Build page tree and fallback to the default language if the localized page doesn't exist
301
330
  */
302
- buildI18n: (options: BaseOptions<Page, Meta> & {
303
- id?: string;
304
- storages: Record<string, ContentStorage<Page, Meta>>;
331
+ buildI18n: (options: BaseOptions & {
332
+ storages: Record<string, ContentStorage>;
305
333
  }) => Record<string, Root>;
306
334
  }
307
335
  declare function createPageTreeBuilder(getUrl: UrlFn): PageTreeBuilder;
308
336
 
309
- export { type BaseOptions, type ContentStorage, type FileInfo, FileSystem, type FolderInfo, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type Meta, type MetaData, type MetaFile, type Page, type PageData, type PageFile, type PageTreeBuilder, type PageTreeBuilderContext, type PageTreeTransformer, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loadFiles, loader, parseFilePath, parseFolderPath };
337
+ export { type BaseOptions, type ContentStorage, type FileInfo, FileSystem, type FolderInfo, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type LoaderPlugin, type LoaderPlugins, type Meta, type MetaData, type MetaFile, type Page, type PageData, type PageFile, type PageTreeBuilder, type PageTreeBuilderContext, type PageTreeTransformer, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, buildPlugins, createGetUrl, createPageTreeBuilder, getSlugs, loadFiles, loader, parseFilePath };
@@ -1,48 +1,20 @@
1
+ import {
2
+ iconPlugin
3
+ } from "../chunk-DDDU7USP.js";
1
4
  import {
2
5
  basename,
3
6
  dirname,
4
7
  extname,
5
8
  joinPath,
6
9
  parseFilePath,
7
- parseFolderPath,
8
10
  slash,
9
11
  splitPath
10
- } from "../chunk-BDG7Y4PS.js";
12
+ } from "../chunk-Z5V4JSQY.js";
11
13
  import {
12
14
  normalizeUrl
13
15
  } from "../chunk-PFNP6PEB.js";
14
16
  import "../chunk-JSBRDJBE.js";
15
17
 
16
- // src/source/page-tree/legacy.ts
17
- function legacyTransformer(transformer) {
18
- return {
19
- file(node, file) {
20
- if (!transformer.attachFile) return node;
21
- const content = file ? this.storage.read(file) : void 0;
22
- return transformer.attachFile(
23
- node,
24
- content?.format === "page" ? content : void 0
25
- );
26
- },
27
- folder(node, folderPath, metaPath) {
28
- if (!transformer.attachFolder) return node;
29
- const files = this.storage.readDir(folderPath) ?? [];
30
- const meta = metaPath ? this.storage.read(metaPath) : void 0;
31
- return transformer.attachFolder(
32
- node,
33
- {
34
- children: files.flatMap((file) => this.storage.read(file) ?? [])
35
- },
36
- meta?.format === "meta" ? meta : void 0
37
- );
38
- },
39
- separator(node) {
40
- if (!transformer.attachSeparator) return node;
41
- return transformer.attachSeparator(node);
42
- }
43
- };
44
- }
45
-
46
18
  // src/source/page-tree/transformer-fallback.ts
47
19
  function transformerFallback() {
48
20
  const addedFiles = /* @__PURE__ */ new Set();
@@ -105,13 +77,13 @@ function buildAll(paths, ctx, reversed = false) {
105
77
  }
106
78
  function resolveFolderItem(folderPath, item, ctx, idx) {
107
79
  if (item === rest || item === restReversed) return item;
108
- const { options, resolveName } = ctx;
80
+ const { resolveName } = ctx;
109
81
  let match = separator.exec(item);
110
82
  if (match?.groups) {
111
83
  let node = {
112
84
  $id: `${folderPath}#${idx}`,
113
85
  type: "separator",
114
- icon: options.resolveIcon?.(match.groups.icon),
86
+ icon: match.groups.icon,
115
87
  name: match.groups.name
116
88
  };
117
89
  for (const transformer of ctx.transformers) {
@@ -126,7 +98,7 @@ function resolveFolderItem(folderPath, item, ctx, idx) {
126
98
  const isRelative = url.startsWith("/") || url.startsWith("#") || url.startsWith(".");
127
99
  let node = {
128
100
  type: "page",
129
- icon: options.resolveIcon?.(icon),
101
+ icon,
130
102
  name,
131
103
  url,
132
104
  external: !isRelative
@@ -203,7 +175,7 @@ function buildFolderNode(folderPath, isGlobalRoot, ctx) {
203
175
  let node = {
204
176
  type: "folder",
205
177
  name,
206
- icon: options.resolveIcon?.(meta?.data.icon) ?? index?.icon,
178
+ icon: meta?.data.icon ?? index?.icon,
207
179
  root: meta?.data.root,
208
180
  defaultOpen: meta?.data.defaultOpen,
209
181
  description: meta?.data.description,
@@ -230,7 +202,7 @@ function buildFileNode(path, ctx) {
230
202
  type: "page",
231
203
  name: title ?? pathToName(basename(path, extname(path))),
232
204
  description,
233
- icon: options.resolveIcon?.(icon),
205
+ icon,
234
206
  url: getUrl(page.slugs, locale),
235
207
  $ref: !options.noRef ? {
236
208
  file: path
@@ -257,9 +229,9 @@ function build(id, ctx) {
257
229
  }
258
230
  function createPageTreeBuilder(getUrl) {
259
231
  function getTransformers(options, generateFallback) {
260
- const transformers = [legacyTransformer(options)];
261
- if (options.transformers) {
262
- transformers.push(...options.transformers);
232
+ const transformers = [];
233
+ for (const plugin of options.plugins ?? []) {
234
+ if (plugin.transformPageTree) transformers.push(plugin.transformPageTree);
263
235
  }
264
236
  if (generateFallback) {
265
237
  transformers.push(transformerFallback());
@@ -401,7 +373,7 @@ var parsers = {
401
373
  }
402
374
  };
403
375
  function loadFiles(files, options, i18n) {
404
- const { buildFile, transformers = [] } = options;
376
+ const { buildFile, plugins = [] } = options;
405
377
  const parser = parsers[i18n.parser ?? "dot"];
406
378
  const storages = {};
407
379
  const normalized = files.map(
@@ -424,11 +396,11 @@ function loadFiles(files, options, i18n) {
424
396
  const [path, locale = i18n.defaultLanguage] = parser(item.path);
425
397
  if (locale === lang) storage.write(path, item);
426
398
  }
427
- for (const transformer of transformers) {
428
- transformer({
429
- storage,
430
- options
431
- });
399
+ const context = {
400
+ storage
401
+ };
402
+ for (const plugin of plugins) {
403
+ plugin.transformStorage?.(context);
432
404
  }
433
405
  storages[lang] = storage;
434
406
  }
@@ -442,6 +414,98 @@ function normalizePath(path) {
442
414
  return segments.join("/");
443
415
  }
444
416
 
417
+ // src/source/plugins/index.ts
418
+ function buildPlugins(plugins) {
419
+ return plugins;
420
+ }
421
+
422
+ // src/source/plugins/slugs.ts
423
+ function slugsPlugin(slugsFn) {
424
+ function isIndex(file) {
425
+ return basename(file, extname(file)) === "index";
426
+ }
427
+ return {
428
+ transformStorage({ storage }) {
429
+ const indexFiles = /* @__PURE__ */ new Set();
430
+ const taken = /* @__PURE__ */ new Set();
431
+ const autoIndex = slugsFn === void 0;
432
+ for (const path of storage.getFiles()) {
433
+ const file = storage.read(path);
434
+ if (!file || file.format !== "page" || file.slugs) continue;
435
+ if (isIndex(path) && autoIndex) {
436
+ indexFiles.add(path);
437
+ continue;
438
+ }
439
+ file.slugs = slugsFn ? slugsFn(parseFilePath(path)) : getSlugs(path);
440
+ const key = file.slugs.join("/");
441
+ if (taken.has(key)) throw new Error("Duplicated slugs");
442
+ taken.add(key);
443
+ }
444
+ for (const path of indexFiles) {
445
+ const file = storage.read(path);
446
+ if (file?.format !== "page") continue;
447
+ file.slugs = getSlugs(path);
448
+ if (taken.has(file.slugs.join("/"))) file.slugs.push("index");
449
+ }
450
+ }
451
+ };
452
+ }
453
+
454
+ // src/source/plugins/compat.ts
455
+ function compatPlugin(loader2, {
456
+ attachFile,
457
+ attachSeparator,
458
+ attachFolder,
459
+ transformers
460
+ }) {
461
+ const chunk = [];
462
+ chunk.push({
463
+ transformPageTree: {
464
+ file(node, file) {
465
+ if (!attachFile) return node;
466
+ const content = file ? this.storage.read(file) : void 0;
467
+ return attachFile(
468
+ node,
469
+ content?.format === "page" ? content : void 0
470
+ );
471
+ },
472
+ folder(node, folderPath, metaPath) {
473
+ if (!attachFolder) return node;
474
+ const files = this.storage.readDir(folderPath) ?? [];
475
+ const meta = metaPath ? this.storage.read(metaPath) : void 0;
476
+ return attachFolder(
477
+ node,
478
+ {
479
+ children: files.flatMap((file) => this.storage.read(file) ?? [])
480
+ },
481
+ meta?.format === "meta" ? meta : void 0
482
+ );
483
+ },
484
+ separator(node) {
485
+ if (!attachSeparator) return node;
486
+ return attachSeparator(node);
487
+ }
488
+ }
489
+ });
490
+ for (const transformer of loader2.transformers ?? []) {
491
+ chunk.push(fromStorageTransformer(transformer));
492
+ }
493
+ for (const transformer of transformers ?? []) {
494
+ chunk.push(fromPageTreeTransformer(transformer));
495
+ }
496
+ return chunk;
497
+ }
498
+ function fromPageTreeTransformer(transformer) {
499
+ return {
500
+ transformPageTree: transformer
501
+ };
502
+ }
503
+ function fromStorageTransformer(transformer) {
504
+ return {
505
+ transformStorage: transformer
506
+ };
507
+ }
508
+
445
509
  // src/source/loader.ts
446
510
  function indexPages(storages, getUrl) {
447
511
  const result = {
@@ -500,40 +564,20 @@ function createOutput(options) {
500
564
  if (!options.url && !options.baseUrl) {
501
565
  console.warn("`loader()` now requires a `baseUrl` option to be defined.");
502
566
  }
503
- const {
504
- source,
505
- baseUrl = "/",
506
- i18n,
507
- slugs: slugsFn,
508
- url: urlFn,
509
- transformers = []
510
- } = options;
567
+ const { source, baseUrl = "/", i18n, slugs: slugsFn, url: urlFn } = options;
511
568
  const getUrl = urlFn ? (...args) => normalizeUrl(urlFn(...args)) : createGetUrl(baseUrl, i18n);
512
569
  const defaultLanguage = i18n?.defaultLanguage ?? "";
513
570
  const files = loadSource(source);
514
- const transformerSlugs = ({ storage }) => {
515
- const indexFiles = /* @__PURE__ */ new Set();
516
- const taken = /* @__PURE__ */ new Set();
517
- const autoIndex = slugsFn === void 0;
518
- for (const path of storage.getFiles()) {
519
- const file = storage.read(path);
520
- if (!file || file.format !== "page" || file.slugs) continue;
521
- if (isIndex(path) && autoIndex) {
522
- indexFiles.add(path);
523
- continue;
524
- }
525
- file.slugs = slugsFn ? slugsFn(parseFilePath(path)) : getSlugs(path);
526
- const key = file.slugs.join("/");
527
- if (taken.has(key)) throw new Error("Duplicated slugs");
528
- taken.add(key);
529
- }
530
- for (const path of indexFiles) {
531
- const file = storage.read(path);
532
- if (file?.format !== "page") continue;
533
- file.slugs = getSlugs(path);
534
- if (taken.has(file.slugs.join("/"))) file.slugs.push("index");
535
- }
536
- };
571
+ const plugins = [slugsPlugin(slugsFn)];
572
+ if (options.icon) {
573
+ plugins.push(iconPlugin(options.icon));
574
+ }
575
+ if (options.plugins) {
576
+ plugins.push(...buildPlugins(options.plugins));
577
+ }
578
+ if (options.pageTree) {
579
+ plugins.push(...compatPlugin(options, options.pageTree));
580
+ }
537
581
  const storages = loadFiles(
538
582
  files,
539
583
  {
@@ -554,7 +598,7 @@ function createOutput(options) {
554
598
  data: file.data
555
599
  };
556
600
  },
557
- transformers: [transformerSlugs, ...transformers]
601
+ plugins
558
602
  },
559
603
  i18n ?? {
560
604
  defaultLanguage,
@@ -570,7 +614,7 @@ function createOutput(options) {
570
614
  get pageTree() {
571
615
  pageTree ??= builder.buildI18n({
572
616
  storages,
573
- resolveIcon: options.icon,
617
+ plugins,
574
618
  ...options.pageTree
575
619
  });
576
620
  return i18n ? pageTree : pageTree[defaultLanguage];
@@ -599,10 +643,12 @@ function createOutput(options) {
599
643
  hash
600
644
  };
601
645
  },
602
- getPages(language = defaultLanguage) {
646
+ getPages(language) {
603
647
  const pages = [];
604
648
  for (const [key, value] of walker.pages.entries()) {
605
- if (key.startsWith(`${language}.`)) pages.push(value);
649
+ if (language === void 0 || key.startsWith(`${language}.`)) {
650
+ pages.push(value);
651
+ }
606
652
  }
607
653
  return pages;
608
654
  },
@@ -676,9 +722,6 @@ function fileToPage(file, getUrl, locale) {
676
722
  };
677
723
  }
678
724
  var GroupRegex = /^\(.+\)$/;
679
- function isIndex(file) {
680
- return basename(file, extname(file)) === "index";
681
- }
682
725
  function getSlugs(file) {
683
726
  if (typeof file !== "string") return getSlugs(file.path);
684
727
  const dir = dirname(file);
@@ -701,6 +744,5 @@ export {
701
744
  getSlugs,
702
745
  loadFiles,
703
746
  loader,
704
- parseFilePath,
705
- parseFolderPath
747
+ parseFilePath
706
748
  };
@@ -0,0 +1,14 @@
1
+ import { LoaderPlugin } from '../index.js';
2
+ import { icons } from 'lucide-react';
3
+ import '../../definitions-Q95-psoo.js';
4
+ import 'react';
5
+ import '../../i18n/index.js';
6
+
7
+ /**
8
+ * Convert icon names into Lucide Icons, requires `lucide-react` to be installed.
9
+ */
10
+ declare function lucideIconsPlugin(options?: {
11
+ defaultIcon?: keyof typeof icons;
12
+ }): LoaderPlugin;
13
+
14
+ export { lucideIconsPlugin };
@@ -0,0 +1,23 @@
1
+ import {
2
+ iconPlugin
3
+ } from "../../chunk-DDDU7USP.js";
4
+ import "../../chunk-JSBRDJBE.js";
5
+
6
+ // src/source/plugins/lucide-icons.ts
7
+ import { icons } from "lucide-react";
8
+ import { createElement } from "react";
9
+ function lucideIconsPlugin(options = {}) {
10
+ const { defaultIcon } = options;
11
+ return iconPlugin((icon = defaultIcon) => {
12
+ if (icon === void 0) return;
13
+ const Icon = icons[icon];
14
+ if (!icon) {
15
+ console.warn(`[lucide-icons-plugin] Unknown icon detected: ${icon}.`);
16
+ return;
17
+ }
18
+ return createElement(Icon);
19
+ });
20
+ }
21
+ export {
22
+ lucideIconsPlugin
23
+ };
package/dist/toc.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, RefObject, AnchorHTMLAttributes } from 'react';
3
- import { T as TableOfContents } from './get-toc-Cr2URuiP.js';
4
- import 'unified';
5
- import 'vfile';
6
3
 
4
+ interface TOCItemType {
5
+ title: ReactNode;
6
+ url: string;
7
+ depth: number;
8
+ }
9
+ type TableOfContents = TOCItemType[];
7
10
  /**
8
11
  * The estimated active heading ID
9
12
  */
@@ -37,4 +40,4 @@ interface TOCItemProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'hr
37
40
  }
38
41
  declare const TOCItem: react.ForwardRefExoticComponent<TOCItemProps & react.RefAttributes<HTMLAnchorElement>>;
39
42
 
40
- export { AnchorProvider, type AnchorProviderProps, ScrollProvider, type ScrollProviderProps, TOCItem, type TOCItemProps, useActiveAnchor, useActiveAnchors };
43
+ export { AnchorProvider, type AnchorProviderProps, ScrollProvider, type ScrollProviderProps, TOCItem, type TOCItemProps, type TOCItemType, type TableOfContents, useActiveAnchor, useActiveAnchors };