fumadocs-core 15.2.13 → 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 {
@@ -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
  /**
@@ -162,10 +153,9 @@ interface LoaderOutput<Config extends LoaderConfig> {
162
153
  }
163
154
  declare function createGetUrl(baseUrl: string, i18n?: I18nConfig): UrlFn;
164
155
  declare function getSlugs(info: FileInfo): string[];
165
- type InferSourceConfig<T> = T extends Source<infer Config> ? Config : never;
166
- declare function loader<Options extends LoaderOptions>(options: Options): LoaderOutput<{
167
- source: InferSourceConfig<Options['source']>;
168
- 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;
169
159
  }>;
170
160
 
171
161
  interface MetaData {
@@ -188,23 +178,23 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
188
178
  */
189
179
  type UrlFn = (slugs: string[], locale?: string) => string;
190
180
 
191
- interface MetaFile {
181
+ interface MetaFile<Data extends MetaData = MetaData> {
192
182
  file: FileInfo;
193
183
  format: 'meta';
194
- data: MetaData;
184
+ data: Data;
195
185
  }
196
- interface PageFile {
186
+ interface PageFile<Data extends PageData = PageData> {
197
187
  file: FileInfo;
198
188
  format: 'page';
199
189
  data: {
200
190
  slugs: string[];
201
- data: PageData;
191
+ data: Data;
202
192
  };
203
193
  }
204
194
  type File = MetaFile | PageFile;
205
- interface Folder {
195
+ interface Folder<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
206
196
  file: FolderInfo;
207
- children: (File | Folder)[];
197
+ children: (MetaFile<Meta> | PageFile<Page> | Folder<Page, Meta>)[];
208
198
  }
209
199
  /**
210
200
  * A virtual file system that solves inconsistent behaviours
@@ -213,7 +203,7 @@ interface Folder {
213
203
  */
214
204
  declare class Storage {
215
205
  files: Map<string, File>;
216
- folders: Map<string, Folder>;
206
+ folders: Map<string, Folder<PageData, MetaData>>;
217
207
  private rootFolder;
218
208
  constructor();
219
209
  /**
@@ -232,33 +222,31 @@ declare class Storage {
232
222
  makeDir(path: string): void;
233
223
  }
234
224
 
235
- type fileSystem_File = File;
236
- type fileSystem_Folder = Folder;
237
- type fileSystem_MetaFile = MetaFile;
238
- 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>;
239
228
  type fileSystem_Storage = Storage;
240
229
  declare const fileSystem_Storage: typeof Storage;
241
230
  declare namespace fileSystem {
242
- 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 };
243
232
  }
244
233
 
245
- interface Options {
234
+ interface BaseOptions<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
246
235
  /**
247
236
  * Remove references to the file path of original nodes (`$ref`)
248
237
  *
249
238
  * @defaultValue false
250
239
  */
251
240
  noRef?: boolean;
252
- attachFile?: (node: Item, file?: PageFile) => Item;
253
- 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;
254
243
  attachSeparator?: (node: Separator) => Separator;
255
- getUrl: UrlFn;
256
244
  resolveIcon?: (icon: string | undefined) => ReactElement | undefined;
257
245
  }
258
- interface BuildPageTreeOptions extends Options {
246
+ interface BuildPageTreeOptions extends BaseOptions {
259
247
  storage: Storage;
260
248
  }
261
- interface BuildPageTreeOptionsWithI18n extends Options {
249
+ interface BuildPageTreeOptionsWithI18n extends BaseOptions {
262
250
  storages: Record<string, Storage>;
263
251
  i18n: I18nConfig;
264
252
  }
@@ -269,6 +257,6 @@ interface PageTreeBuilder {
269
257
  */
270
258
  buildI18n: (options: BuildPageTreeOptionsWithI18n) => Record<string, Root>;
271
259
  }
272
- declare function createPageTreeBuilder(): PageTreeBuilder;
260
+ declare function createPageTreeBuilder(getUrl: UrlFn): PageTreeBuilder;
273
261
 
274
- 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.13",
3
+ "version": "15.2.14",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",