fumadocs-core 15.2.12 → 15.2.14

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.
@@ -21,6 +21,12 @@ interface I18nConfig {
21
21
  * @defaultValue 'never'
22
22
  */
23
23
  hideLocale?: 'always' | 'default-locale' | 'never';
24
+ /**
25
+ * Used by `loader()`, specify the way to parse i18n file structure.
26
+ *
27
+ * @defaultValue 'dot'
28
+ */
29
+ parser?: 'dot' | 'dir';
24
30
  }
25
31
 
26
32
  export type { I18nConfig as I };
@@ -1,4 +1,4 @@
1
- import { I as I18nConfig } from '../config-inq6kP6y.js';
1
+ import { I as I18nConfig } from '../config-Cm58P4fz.js';
2
2
  import { NextMiddleware } from 'next/dist/server/web/types';
3
3
 
4
4
  interface MiddlewareOptions extends I18nConfig {
@@ -1,7 +1,7 @@
1
1
  import { TypedDocument, Orama, Language, RawData, create, SearchParams } from '@orama/orama';
2
2
  import { S as StructuredData } from '../remark-structure-FIjTA11P.js';
3
3
  import { S as SortedResult } from '../types-Ch8gnVgO.js';
4
- import { I as I18nConfig } from '../config-inq6kP6y.js';
4
+ import { I as I18nConfig } from '../config-Cm58P4fz.js';
5
5
  import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
6
6
  import 'mdast';
7
7
  import 'unified';
@@ -8,7 +8,7 @@ import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
8
8
  import 'react';
9
9
  import 'unified';
10
10
  import 'vfile';
11
- import '../config-inq6kP6y.js';
11
+ import '../config-Cm58P4fz.js';
12
12
 
13
13
  /**
14
14
  * Flatten tree to an array of page nodes
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { I as I18nConfig } from '../config-inq6kP6y.js';
2
+ import { I as I18nConfig } from '../config-Cm58P4fz.js';
3
3
  import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-bSt6K__E.js';
4
4
 
5
5
  interface FileInfo {
@@ -10,11 +10,11 @@ interface FileInfo {
10
10
  */
11
11
  flattenedPath: string;
12
12
  /**
13
- * Original path of file
13
+ * path of file (unparsed)
14
14
  */
15
15
  path: string;
16
16
  /**
17
- * File name without locale and extension
17
+ * File name without extension
18
18
  */
19
19
  name: string;
20
20
  /**
@@ -43,13 +43,6 @@ interface LoadOptions {
43
43
  transformers?: Transformer[];
44
44
  getSlugs: (info: FileInfo) => string[];
45
45
  }
46
- interface I18nLoadOptions extends LoadOptions {
47
- i18n: {
48
- parser: 'dot' | 'dir';
49
- languages: string[];
50
- defaultLanguage: string;
51
- };
52
- }
53
46
  interface VirtualFile {
54
47
  /**
55
48
  * Relative path
@@ -78,23 +71,21 @@ interface SourceConfig {
78
71
  pageData: PageData;
79
72
  metaData: MetaData;
80
73
  }
81
- interface LoaderOptions {
74
+ interface LoaderOptions<T extends SourceConfig = SourceConfig, I18n extends I18nConfig | undefined = I18nConfig | undefined> {
82
75
  baseUrl: string;
83
- icon?: NonNullable<BuildPageTreeOptions['resolveIcon']>;
76
+ icon?: NonNullable<BaseOptions['resolveIcon']>;
84
77
  slugs?: LoadOptions['getSlugs'];
85
78
  url?: UrlFn;
86
- source: Source<any>;
79
+ source: Source<T>;
87
80
  transformers?: Transformer[];
88
81
  /**
89
82
  * Additional options for page tree builder
90
83
  */
91
- pageTree?: Partial<Omit<BuildPageTreeOptions, 'storage' | 'getUrl'>>;
84
+ pageTree?: Partial<BaseOptions<T['pageData'], T['metaData']>>;
92
85
  /**
93
86
  * Configure i18n
94
87
  */
95
- i18n?: I18nConfig & {
96
- parser?: I18nLoadOptions['i18n']['parser'];
97
- };
88
+ i18n?: I18n;
98
89
  }
99
90
  interface Source<Config extends SourceConfig> {
100
91
  /**
@@ -104,6 +95,9 @@ interface Source<Config extends SourceConfig> {
104
95
  files: VirtualFile[] | (() => VirtualFile[]);
105
96
  }
106
97
  interface Page<Data = PageData> {
98
+ /**
99
+ * Virtualized file path
100
+ */
107
101
  file: FileInfo;
108
102
  slugs: string[];
109
103
  url: string;
@@ -111,6 +105,9 @@ interface Page<Data = PageData> {
111
105
  locale?: string | undefined;
112
106
  }
113
107
  interface Meta<Data = MetaData> {
108
+ /**
109
+ * Virtualized file path
110
+ */
114
111
  file: FileInfo;
115
112
  data: Data;
116
113
  }
@@ -156,10 +153,9 @@ interface LoaderOutput<Config extends LoaderConfig> {
156
153
  }
157
154
  declare function createGetUrl(baseUrl: string, i18n?: I18nConfig): UrlFn;
158
155
  declare function getSlugs(info: FileInfo): string[];
159
- type InferSourceConfig<T> = T extends Source<infer Config> ? Config : never;
160
- declare function loader<Options extends LoaderOptions>(options: Options): LoaderOutput<{
161
- source: InferSourceConfig<Options['source']>;
162
- i18n: Options['i18n'] extends I18nConfig ? true : false;
156
+ declare function loader<Config extends SourceConfig, I18n extends I18nConfig | undefined = undefined>(options: LoaderOptions<Config, I18n>): LoaderOutput<{
157
+ source: Config;
158
+ i18n: I18n extends I18nConfig ? true : false;
163
159
  }>;
164
160
 
165
161
  interface MetaData {
@@ -182,23 +178,23 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
182
178
  */
183
179
  type UrlFn = (slugs: string[], locale?: string) => string;
184
180
 
185
- interface MetaFile {
181
+ interface MetaFile<Data extends MetaData = MetaData> {
186
182
  file: FileInfo;
187
183
  format: 'meta';
188
- data: MetaData;
184
+ data: Data;
189
185
  }
190
- interface PageFile {
186
+ interface PageFile<Data extends PageData = PageData> {
191
187
  file: FileInfo;
192
188
  format: 'page';
193
189
  data: {
194
190
  slugs: string[];
195
- data: PageData;
191
+ data: Data;
196
192
  };
197
193
  }
198
194
  type File = MetaFile | PageFile;
199
- interface Folder {
195
+ interface Folder<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
200
196
  file: FolderInfo;
201
- children: (File | Folder)[];
197
+ children: (MetaFile<Meta> | PageFile<Page> | Folder<Page, Meta>)[];
202
198
  }
203
199
  /**
204
200
  * A virtual file system that solves inconsistent behaviours
@@ -207,7 +203,7 @@ interface Folder {
207
203
  */
208
204
  declare class Storage {
209
205
  files: Map<string, File>;
210
- folders: Map<string, Folder>;
206
+ folders: Map<string, Folder<PageData, MetaData>>;
211
207
  private rootFolder;
212
208
  constructor();
213
209
  /**
@@ -226,33 +222,31 @@ declare class Storage {
226
222
  makeDir(path: string): void;
227
223
  }
228
224
 
229
- type fileSystem_File = File;
230
- type fileSystem_Folder = Folder;
231
- type fileSystem_MetaFile = MetaFile;
232
- type fileSystem_PageFile = PageFile;
225
+ type fileSystem_Folder<Page extends PageData = PageData, Meta extends MetaData = MetaData> = Folder<Page, Meta>;
226
+ type fileSystem_MetaFile<Data extends MetaData = MetaData> = MetaFile<Data>;
227
+ type fileSystem_PageFile<Data extends PageData = PageData> = PageFile<Data>;
233
228
  type fileSystem_Storage = Storage;
234
229
  declare const fileSystem_Storage: typeof Storage;
235
230
  declare namespace fileSystem {
236
- export { type fileSystem_File as File, type fileSystem_Folder as Folder, type fileSystem_MetaFile as MetaFile, type fileSystem_PageFile as PageFile, fileSystem_Storage as Storage };
231
+ export { type fileSystem_Folder as Folder, type fileSystem_MetaFile as MetaFile, type fileSystem_PageFile as PageFile, fileSystem_Storage as Storage };
237
232
  }
238
233
 
239
- interface Options {
234
+ interface BaseOptions<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
240
235
  /**
241
236
  * Remove references to the file path of original nodes (`$ref`)
242
237
  *
243
238
  * @defaultValue false
244
239
  */
245
240
  noRef?: boolean;
246
- attachFile?: (node: Item, file?: PageFile) => Item;
247
- attachFolder?: (node: Folder$1, folder: Folder, meta?: MetaFile) => Folder$1;
241
+ attachFile?: (node: Item, file?: PageFile<Page>) => Item;
242
+ attachFolder?: (node: Folder$1, folder: Folder<Page, Meta>, meta?: MetaFile<Meta>) => Folder$1;
248
243
  attachSeparator?: (node: Separator) => Separator;
249
- getUrl: UrlFn;
250
244
  resolveIcon?: (icon: string | undefined) => ReactElement | undefined;
251
245
  }
252
- interface BuildPageTreeOptions extends Options {
246
+ interface BuildPageTreeOptions extends BaseOptions {
253
247
  storage: Storage;
254
248
  }
255
- interface BuildPageTreeOptionsWithI18n extends Options {
249
+ interface BuildPageTreeOptionsWithI18n extends BaseOptions {
256
250
  storages: Record<string, Storage>;
257
251
  i18n: I18nConfig;
258
252
  }
@@ -263,6 +257,6 @@ interface PageTreeBuilder {
263
257
  */
264
258
  buildI18n: (options: BuildPageTreeOptionsWithI18n) => Record<string, Root>;
265
259
  }
266
- declare function createPageTreeBuilder(): PageTreeBuilder;
260
+ declare function createPageTreeBuilder(getUrl: UrlFn): PageTreeBuilder;
267
261
 
268
- export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileInfo, fileSystem as FileSystem, type FolderInfo, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type Meta, type MetaData, type Page, type PageData, type PageTreeBuilder, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loadFiles, loader, parseFilePath, parseFolderPath };
262
+ export { type BaseOptions, type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileInfo, fileSystem as FileSystem, type FolderInfo, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type Meta, type MetaData, type Page, type PageData, type PageTreeBuilder, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loadFiles, loader, parseFilePath, parseFolderPath };
@@ -140,7 +140,7 @@ function buildFileNode(file, ctx) {
140
140
  name: file.data.data.title ?? pathToName(file.file.name),
141
141
  description: file.data.data.description,
142
142
  icon: ctx.options.resolveIcon?.(file.data.data.icon),
143
- url: ctx.options.getUrl(file.data.slugs, ctx.locale),
143
+ url: ctx.getUrl(file.data.slugs, ctx.locale),
144
144
  $ref: !ctx.options.noRef ? {
145
145
  file: file.file.path
146
146
  } : void 0
@@ -156,19 +156,21 @@ function build(ctx) {
156
156
  children: folder.children
157
157
  };
158
158
  }
159
- function createPageTreeBuilder() {
159
+ function createPageTreeBuilder(getUrl) {
160
160
  return {
161
161
  build(options) {
162
162
  return build({
163
163
  options,
164
164
  builder: this,
165
- storage: options.storage
165
+ storage: options.storage,
166
+ getUrl
166
167
  });
167
168
  },
168
169
  buildI18n({ i18n, ...options }) {
169
170
  const entries = i18n.languages.map((lang) => {
170
171
  const tree = build({
171
172
  options,
173
+ getUrl,
172
174
  builder: this,
173
175
  locale: lang,
174
176
  storage: options.storages[i18n.defaultLanguage],
@@ -429,7 +431,7 @@ function createOutput(options) {
429
431
  })
430
432
  };
431
433
  const walker = indexPages(storages, getUrl, options.i18n);
432
- const builder = createPageTreeBuilder();
434
+ const builder = createPageTreeBuilder(getUrl);
433
435
  let pageTree;
434
436
  return {
435
437
  _i18n: options.i18n,
@@ -438,7 +440,6 @@ function createOutput(options) {
438
440
  pageTree ??= builder.buildI18n({
439
441
  storages,
440
442
  resolveIcon: options.icon,
441
- getUrl,
442
443
  i18n: options.i18n,
443
444
  ...options.pageTree
444
445
  });
@@ -446,7 +447,6 @@ function createOutput(options) {
446
447
  pageTree ??= builder.build({
447
448
  storage: storages[""],
448
449
  resolveIcon: options.icon,
449
- getUrl,
450
450
  ...options.pageTree
451
451
  });
452
452
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "15.2.12",
3
+ "version": "15.2.14",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -97,19 +97,19 @@
97
97
  "@algolia/client-search": "4.24.0",
98
98
  "@mdx-js/mdx": "^3.1.0",
99
99
  "@oramacloud/client": "^2.1.4",
100
- "@tanstack/react-router": "^1.117.1",
100
+ "@tanstack/react-router": "^1.119.0",
101
101
  "@types/estree-jsx": "^1.0.5",
102
102
  "@types/hast": "^3.0.4",
103
103
  "@types/mdast": "^4.0.3",
104
104
  "@types/negotiator": "^0.6.3",
105
- "@types/node": "22.15.2",
105
+ "@types/node": "22.15.3",
106
106
  "@types/react": "^19.1.2",
107
- "@types/react-dom": "^19.1.2",
107
+ "@types/react-dom": "^19.1.3",
108
108
  "algoliasearch": "4.24.0",
109
109
  "mdast-util-mdx-jsx": "^3.2.0",
110
110
  "mdast-util-mdxjs-esm": "^2.0.1",
111
111
  "next": "^15.3.1",
112
- "react-router": "^7.5.2",
112
+ "react-router": "^7.5.3",
113
113
  "remark-mdx": "^3.1.0",
114
114
  "remark-rehype": "^11.1.2",
115
115
  "typescript": "^5.8.3",