fumadocs-core 13.0.1 → 13.0.3
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.
- package/dist/dynamic-link.js +1 -1
- package/dist/source/index.d.ts +53 -48
- package/dist/source/index.js +12 -16
- package/package.json +1 -1
package/dist/dynamic-link.js
CHANGED
|
@@ -12,7 +12,7 @@ var DynamicLink = forwardRef(
|
|
|
12
12
|
({ href, ...props }, ref) => {
|
|
13
13
|
const params = useParams();
|
|
14
14
|
const url = useMemo(() => {
|
|
15
|
-
return href?.replace(/\[
|
|
15
|
+
return href?.replace(/\[.*]/, (key) => {
|
|
16
16
|
const mappedKey = key.slice(1, -1);
|
|
17
17
|
const value = mappedKey in params ? params[mappedKey] : "undefined";
|
|
18
18
|
return typeof value === "string" ? value : value.join("/");
|
package/dist/source/index.d.ts
CHANGED
|
@@ -20,45 +20,6 @@ interface FileInfo {
|
|
|
20
20
|
declare function parseFilePath(path: string): FileInfo;
|
|
21
21
|
declare function parseFolderPath(path: string): FileInfo;
|
|
22
22
|
|
|
23
|
-
interface File {
|
|
24
|
-
file: FileInfo;
|
|
25
|
-
format: 'meta' | 'page';
|
|
26
|
-
data: Record<string, unknown>;
|
|
27
|
-
}
|
|
28
|
-
interface Folder {
|
|
29
|
-
file: FileInfo;
|
|
30
|
-
children: (File | Folder)[];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* A virtual file system that solves inconsistent behaviours
|
|
34
|
-
*
|
|
35
|
-
* Some source providers may not provide the full file structure, this will cause inconsistent outputs for page builder and other transformers
|
|
36
|
-
*/
|
|
37
|
-
declare class Storage {
|
|
38
|
-
files: Map<string, File>;
|
|
39
|
-
folders: Map<string, Folder>;
|
|
40
|
-
private rootFolder;
|
|
41
|
-
constructor();
|
|
42
|
-
/**
|
|
43
|
-
* @param path - flattened path
|
|
44
|
-
* @param format - file format
|
|
45
|
-
*/
|
|
46
|
-
read(path: string, format: string): File | undefined;
|
|
47
|
-
readDir(path: string): Folder | undefined;
|
|
48
|
-
root(): Folder;
|
|
49
|
-
write(path: string, format: 'meta' | 'page', data: Record<string, unknown>): void;
|
|
50
|
-
list(): File[];
|
|
51
|
-
makeDir(path: string): void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type fileSystem_File = File;
|
|
55
|
-
type fileSystem_Folder = Folder;
|
|
56
|
-
type fileSystem_Storage = Storage;
|
|
57
|
-
declare const fileSystem_Storage: typeof Storage;
|
|
58
|
-
declare namespace fileSystem {
|
|
59
|
-
export { type fileSystem_File as File, type fileSystem_Folder as Folder, fileSystem_Storage as Storage };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
23
|
interface LoadOptions {
|
|
63
24
|
transformers?: Transformer[];
|
|
64
25
|
rootDir?: string;
|
|
@@ -168,18 +129,62 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
|
|
|
168
129
|
* @internal
|
|
169
130
|
*/
|
|
170
131
|
type UrlFn = (slugs: string[], locale?: string) => string;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
132
|
+
|
|
133
|
+
interface MetaFile {
|
|
134
|
+
file: FileInfo;
|
|
135
|
+
format: 'meta';
|
|
136
|
+
data: {
|
|
176
137
|
data: MetaData;
|
|
177
138
|
};
|
|
178
|
-
|
|
139
|
+
}
|
|
140
|
+
interface PageFile {
|
|
141
|
+
file: FileInfo;
|
|
142
|
+
format: 'page';
|
|
143
|
+
data: {
|
|
179
144
|
slugs: string[];
|
|
180
145
|
data: PageData;
|
|
181
146
|
};
|
|
182
147
|
}
|
|
148
|
+
type File = MetaFile | PageFile;
|
|
149
|
+
interface Folder {
|
|
150
|
+
file: FileInfo;
|
|
151
|
+
children: (File | Folder)[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A virtual file system that solves inconsistent behaviours
|
|
155
|
+
*
|
|
156
|
+
* Some source providers may not provide the full file structure, this will cause inconsistent outputs for page builder and other transformers
|
|
157
|
+
*/
|
|
158
|
+
declare class Storage {
|
|
159
|
+
files: Map<string, File>;
|
|
160
|
+
folders: Map<string, Folder>;
|
|
161
|
+
private rootFolder;
|
|
162
|
+
constructor();
|
|
163
|
+
/**
|
|
164
|
+
* @param path - flattened path
|
|
165
|
+
* @param format - file format
|
|
166
|
+
*/
|
|
167
|
+
read<F extends File['format']>(path: string, format: F): Extract<File, {
|
|
168
|
+
format: F;
|
|
169
|
+
}> | undefined;
|
|
170
|
+
readDir(path: string): Folder | undefined;
|
|
171
|
+
root(): Folder;
|
|
172
|
+
write<F extends File['format']>(path: string, format: F, data: Extract<File, {
|
|
173
|
+
format: F;
|
|
174
|
+
}>['data']): void;
|
|
175
|
+
list(): File[];
|
|
176
|
+
makeDir(path: string): void;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
type fileSystem_File = File;
|
|
180
|
+
type fileSystem_Folder = Folder;
|
|
181
|
+
type fileSystem_MetaFile = MetaFile;
|
|
182
|
+
type fileSystem_PageFile = PageFile;
|
|
183
|
+
type fileSystem_Storage = Storage;
|
|
184
|
+
declare const fileSystem_Storage: typeof Storage;
|
|
185
|
+
declare namespace fileSystem {
|
|
186
|
+
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 };
|
|
187
|
+
}
|
|
183
188
|
|
|
184
189
|
interface BuildPageTreeOptions {
|
|
185
190
|
/**
|
|
@@ -188,8 +193,8 @@ interface BuildPageTreeOptions {
|
|
|
188
193
|
* @defaultValue false
|
|
189
194
|
*/
|
|
190
195
|
attachFolderIds?: boolean;
|
|
191
|
-
attachFile?: (node: Item, file?:
|
|
192
|
-
attachFolder?: (node: Folder$1, folder: Folder, meta?:
|
|
196
|
+
attachFile?: (node: Item, file?: PageFile) => Item;
|
|
197
|
+
attachFolder?: (node: Folder$1, folder: Folder, meta?: MetaFile) => Folder$1;
|
|
193
198
|
attachSeparator?: (node: Separator) => Separator;
|
|
194
199
|
storage: Storage;
|
|
195
200
|
getUrl: UrlFn;
|
|
@@ -214,4 +219,4 @@ interface PageTreeBuilder {
|
|
|
214
219
|
}
|
|
215
220
|
declare function createPageTreeBuilder(): PageTreeBuilder;
|
|
216
221
|
|
|
217
|
-
export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type
|
|
222
|
+
export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileInfo, fileSystem as FileSystem, 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 };
|
package/dist/source/index.js
CHANGED
|
@@ -104,13 +104,11 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
|
|
|
104
104
|
};
|
|
105
105
|
return [ctx.options.attachFile?.(node) ?? node];
|
|
106
106
|
}
|
|
107
|
+
const isExcept = item.startsWith("!"), isExtract = item.startsWith("...");
|
|
107
108
|
let filename = item;
|
|
108
|
-
const isExcept = item.startsWith("!");
|
|
109
109
|
if (isExcept) {
|
|
110
110
|
filename = item.slice(1);
|
|
111
|
-
}
|
|
112
|
-
const isExtract = item.startsWith("...");
|
|
113
|
-
if (isExtract) {
|
|
111
|
+
} else if (isExtract) {
|
|
114
112
|
filename = item.slice(3);
|
|
115
113
|
}
|
|
116
114
|
const path = resolvePath(folder.file.path, filename);
|
|
@@ -124,7 +122,7 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
|
|
|
124
122
|
}
|
|
125
123
|
return [buildFileNode(itemNode, ctx)];
|
|
126
124
|
}
|
|
127
|
-
function buildFolderNode(folder,
|
|
125
|
+
function buildFolderNode(folder, isGlobalRoot, ctx) {
|
|
128
126
|
const metaPath = resolvePath(folder.file.path, "meta");
|
|
129
127
|
let meta = ctx.storage.read(metaPath, "meta");
|
|
130
128
|
meta = findLocalizedFile(metaPath, "meta", ctx) ?? meta;
|
|
@@ -136,9 +134,9 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
|
|
|
136
134
|
const index = indexFile ? buildFileNode(indexFile, ctx) : void 0;
|
|
137
135
|
let children;
|
|
138
136
|
if (!meta) {
|
|
139
|
-
children = buildAll(folder.children, ctx, !
|
|
137
|
+
children = buildAll(folder.children, ctx, !isGlobalRoot);
|
|
140
138
|
} else {
|
|
141
|
-
const isRoot = metadata?.root ??
|
|
139
|
+
const isRoot = metadata?.root ?? isGlobalRoot;
|
|
142
140
|
const addedNodePaths = /* @__PURE__ */ new Set();
|
|
143
141
|
const resolved = metadata?.pages?.flatMap((item) => {
|
|
144
142
|
return resolveFolderItem(folder, item, ctx, addedNodePaths);
|
|
@@ -159,7 +157,7 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
|
|
|
159
157
|
const node = {
|
|
160
158
|
type: "folder",
|
|
161
159
|
name: metadata?.title ?? index?.name ?? pathToName(folder.file.name, true),
|
|
162
|
-
icon: ctx.options.resolveIcon?.(metadata?.icon),
|
|
160
|
+
icon: ctx.options.resolveIcon?.(metadata?.icon) ?? index?.icon,
|
|
163
161
|
root: metadata?.root,
|
|
164
162
|
defaultOpen: metadata?.defaultOpen,
|
|
165
163
|
index,
|
|
@@ -174,12 +172,11 @@ function buildFolderNode(folder, defaultIsRoot, ctx) {
|
|
|
174
172
|
}
|
|
175
173
|
function buildFileNode(file, ctx) {
|
|
176
174
|
const localized = findLocalizedFile(file.file.flattenedPath, "page", ctx) ?? file;
|
|
177
|
-
const data = localized.data;
|
|
178
175
|
const item = {
|
|
179
176
|
type: "page",
|
|
180
|
-
name: data.data.title,
|
|
181
|
-
icon: ctx.options.resolveIcon?.(data.data.icon),
|
|
182
|
-
url: ctx.options.getUrl(data.slugs, ctx.lang)
|
|
177
|
+
name: localized.data.data.title,
|
|
178
|
+
icon: ctx.options.resolveIcon?.(localized.data.data.icon),
|
|
179
|
+
url: ctx.options.getUrl(localized.data.slugs, ctx.lang)
|
|
183
180
|
};
|
|
184
181
|
return removeUndefined(ctx.options.attachFile?.(item, file) ?? item);
|
|
185
182
|
}
|
|
@@ -420,12 +417,11 @@ function createOutput({
|
|
|
420
417
|
};
|
|
421
418
|
}
|
|
422
419
|
function fileToPage(file, getUrl, locale) {
|
|
423
|
-
const data = file.data;
|
|
424
420
|
return {
|
|
425
421
|
file: file.file,
|
|
426
|
-
url: getUrl(data.slugs, locale),
|
|
427
|
-
slugs: data.slugs,
|
|
428
|
-
data: data.data
|
|
422
|
+
url: getUrl(file.data.slugs, locale),
|
|
423
|
+
slugs: file.data.slugs,
|
|
424
|
+
data: file.data.data
|
|
429
425
|
};
|
|
430
426
|
}
|
|
431
427
|
export {
|