fumadocs-core 15.7.13 → 15.8.1
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/{algolia-KPRGMSJO.js → algolia-Z232AL35.js} +2 -1
- package/dist/breadcrumb.d.ts +6 -4
- package/dist/breadcrumb.js +42 -53
- package/dist/chunk-HV3YIUWE.js +108 -0
- package/dist/{chunk-CNWEGOUF.js → chunk-OTD7MV33.js} +1 -1
- package/dist/{chunk-XMAVUWLD.js → chunk-XOFXGHS4.js} +4 -1
- package/dist/mdx-plugins/index.d.ts +1 -1
- package/dist/mdx-plugins/index.js +3 -3
- package/dist/{orama-cloud-TXCWJTK3.js → orama-cloud-GMFFJOIB.js} +2 -1
- package/dist/search/algolia.d.ts +2 -0
- package/dist/search/algolia.js +3 -1
- package/dist/search/client.d.ts +2 -1
- package/dist/search/client.js +3 -3
- package/dist/search/index.d.ts +26 -0
- package/dist/search/index.js +7 -0
- package/dist/search/orama-cloud.d.ts +2 -0
- package/dist/search/orama-cloud.js +1 -0
- package/dist/search/server.d.ts +14 -10
- package/dist/search/server.js +84 -71
- package/dist/server/index.d.ts +10 -2
- package/dist/server/index.js +9 -73
- package/dist/source/index.d.ts +104 -72
- package/dist/source/index.js +140 -83
- package/dist/{static-PIZYNE45.js → static-UVSWNGTY.js} +2 -2
- package/package.json +16 -12
- package/dist/shared-ORgOfXFw.d.ts +0 -19
package/dist/search/server.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
basename,
|
|
3
|
+
extname
|
|
4
|
+
} from "../chunk-BDG7Y4PS.js";
|
|
1
5
|
import {
|
|
2
6
|
searchAdvanced,
|
|
3
7
|
searchSimple
|
|
4
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-XOFXGHS4.js";
|
|
5
9
|
import "../chunk-ZMWYLUDP.js";
|
|
6
10
|
import {
|
|
7
11
|
createContentHighlighter
|
|
8
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-OTD7MV33.js";
|
|
9
13
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "../chunk-BDG7Y4PS.js";
|
|
14
|
+
findPath
|
|
15
|
+
} from "../chunk-HV3YIUWE.js";
|
|
13
16
|
import "../chunk-JSBRDJBE.js";
|
|
14
17
|
|
|
15
18
|
// src/search/server.ts
|
|
@@ -45,10 +48,19 @@ import {
|
|
|
45
48
|
create,
|
|
46
49
|
insertMultiple
|
|
47
50
|
} from "@orama/orama";
|
|
51
|
+
var simpleSchema = {
|
|
52
|
+
url: "string",
|
|
53
|
+
title: "string",
|
|
54
|
+
breadcrumbs: "string[]",
|
|
55
|
+
description: "string",
|
|
56
|
+
content: "string",
|
|
57
|
+
keywords: "string"
|
|
58
|
+
};
|
|
48
59
|
var advancedSchema = {
|
|
49
60
|
content: "string",
|
|
50
61
|
page_id: "string",
|
|
51
62
|
type: "string",
|
|
63
|
+
breadcrumbs: "string[]",
|
|
52
64
|
tags: "enum[]",
|
|
53
65
|
url: "string",
|
|
54
66
|
embeddings: "vector[512]"
|
|
@@ -70,7 +82,8 @@ async function createDB({
|
|
|
70
82
|
});
|
|
71
83
|
const mapTo = [];
|
|
72
84
|
items.forEach((page) => {
|
|
73
|
-
const
|
|
85
|
+
const pageTag = page.tag ?? [];
|
|
86
|
+
const tags = Array.isArray(pageTag) ? pageTag : [pageTag];
|
|
74
87
|
const data = page.structuredData;
|
|
75
88
|
let id = 0;
|
|
76
89
|
mapTo.push({
|
|
@@ -78,12 +91,14 @@ async function createDB({
|
|
|
78
91
|
page_id: page.id,
|
|
79
92
|
type: "page",
|
|
80
93
|
content: page.title,
|
|
94
|
+
breadcrumbs: page.breadcrumbs,
|
|
81
95
|
tags,
|
|
82
96
|
url: page.url
|
|
83
97
|
});
|
|
98
|
+
const nextId = () => `${page.id}-${id++}`;
|
|
84
99
|
if (page.description) {
|
|
85
100
|
mapTo.push({
|
|
86
|
-
id:
|
|
101
|
+
id: nextId(),
|
|
87
102
|
page_id: page.id,
|
|
88
103
|
tags,
|
|
89
104
|
type: "text",
|
|
@@ -93,7 +108,7 @@ async function createDB({
|
|
|
93
108
|
}
|
|
94
109
|
for (const heading of data.headings) {
|
|
95
110
|
mapTo.push({
|
|
96
|
-
id:
|
|
111
|
+
id: nextId(),
|
|
97
112
|
page_id: page.id,
|
|
98
113
|
type: "heading",
|
|
99
114
|
tags,
|
|
@@ -103,7 +118,7 @@ async function createDB({
|
|
|
103
118
|
}
|
|
104
119
|
for (const content of data.contents) {
|
|
105
120
|
mapTo.push({
|
|
106
|
-
id:
|
|
121
|
+
id: nextId(),
|
|
107
122
|
page_id: page.id,
|
|
108
123
|
tags,
|
|
109
124
|
type: "text",
|
|
@@ -115,13 +130,6 @@ async function createDB({
|
|
|
115
130
|
await insertMultiple(db, mapTo);
|
|
116
131
|
return db;
|
|
117
132
|
}
|
|
118
|
-
var simpleSchema = {
|
|
119
|
-
url: "string",
|
|
120
|
-
title: "string",
|
|
121
|
-
description: "string",
|
|
122
|
-
content: "string",
|
|
123
|
-
keywords: "string"
|
|
124
|
-
};
|
|
125
133
|
async function createDBSimple({
|
|
126
134
|
indexes,
|
|
127
135
|
tokenizer,
|
|
@@ -141,6 +149,7 @@ async function createDBSimple({
|
|
|
141
149
|
items.map((page) => ({
|
|
142
150
|
title: page.title,
|
|
143
151
|
description: page.description,
|
|
152
|
+
breadcrumbs: page.breadcrumbs,
|
|
144
153
|
url: page.url,
|
|
145
154
|
content: page.content,
|
|
146
155
|
keywords: page.keywords
|
|
@@ -150,73 +159,77 @@ async function createDBSimple({
|
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
// src/search/orama/create-from-source.ts
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
structuredData = page.data.structuredData;
|
|
157
|
-
} else if ("load" in page.data && typeof page.data.load === "function") {
|
|
158
|
-
structuredData = (await page.data.load()).structuredData;
|
|
162
|
+
function defaultBuildIndex(source) {
|
|
163
|
+
function isBreadcrumbItem(item) {
|
|
164
|
+
return typeof item === "string" && item.length > 0;
|
|
159
165
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
return async (page) => {
|
|
167
|
+
let breadcrumbs;
|
|
168
|
+
let structuredData;
|
|
169
|
+
if ("structuredData" in page.data) {
|
|
170
|
+
structuredData = page.data.structuredData;
|
|
171
|
+
} else if ("load" in page.data && typeof page.data.load === "function") {
|
|
172
|
+
structuredData = (await page.data.load()).structuredData;
|
|
173
|
+
}
|
|
174
|
+
if (!structuredData)
|
|
175
|
+
throw new Error(
|
|
176
|
+
"Cannot find structured data from page, please define the page to index function."
|
|
177
|
+
);
|
|
178
|
+
const pageTree = source.getPageTree(page.locale);
|
|
179
|
+
const path = findPath(
|
|
180
|
+
pageTree.children,
|
|
181
|
+
(node) => node.type === "page" && node.url === page.url
|
|
163
182
|
);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
183
|
+
if (path) {
|
|
184
|
+
breadcrumbs = [];
|
|
185
|
+
path.pop();
|
|
186
|
+
if (isBreadcrumbItem(pageTree.name)) {
|
|
187
|
+
breadcrumbs.push(pageTree.name);
|
|
188
|
+
}
|
|
189
|
+
for (const segment of path) {
|
|
190
|
+
if (!isBreadcrumbItem(segment.name)) continue;
|
|
191
|
+
breadcrumbs.push(segment.name);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
title: page.data.title ?? basename(page.path, extname(page.path)),
|
|
196
|
+
breadcrumbs,
|
|
197
|
+
description: page.data.description,
|
|
198
|
+
url: page.url,
|
|
199
|
+
id: page.url,
|
|
200
|
+
structuredData
|
|
201
|
+
};
|
|
170
202
|
};
|
|
171
203
|
}
|
|
172
|
-
function createFromSource(source, _buildIndexOrOptions
|
|
173
|
-
const { buildIndex =
|
|
204
|
+
function createFromSource(source, _buildIndexOrOptions, _options) {
|
|
205
|
+
const { buildIndex = defaultBuildIndex(source), ...options } = {
|
|
174
206
|
...typeof _buildIndexOrOptions === "function" ? {
|
|
175
207
|
buildIndex: _buildIndexOrOptions
|
|
176
208
|
} : _buildIndexOrOptions,
|
|
177
209
|
..._options
|
|
178
210
|
};
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
indexes: loaded
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
} else {
|
|
196
|
-
const indexes = source.getPages().map(async (page) => {
|
|
197
|
-
return buildIndex(page);
|
|
211
|
+
if (source._i18n) {
|
|
212
|
+
return createI18nSearchAPI("advanced", {
|
|
213
|
+
...options,
|
|
214
|
+
i18n: source._i18n,
|
|
215
|
+
indexes: async () => {
|
|
216
|
+
const indexes = source.getLanguages().flatMap((entry) => {
|
|
217
|
+
return entry.pages.map(async (page) => ({
|
|
218
|
+
...await buildIndex(page),
|
|
219
|
+
locale: entry.language
|
|
220
|
+
}));
|
|
221
|
+
});
|
|
222
|
+
return Promise.all(indexes);
|
|
223
|
+
}
|
|
198
224
|
});
|
|
199
|
-
server = Promise.all(indexes).then(
|
|
200
|
-
(loaded) => createSearchAPI("advanced", {
|
|
201
|
-
...options,
|
|
202
|
-
indexes: loaded
|
|
203
|
-
})
|
|
204
|
-
);
|
|
205
225
|
}
|
|
206
|
-
return {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return (await server).GET(...args);
|
|
212
|
-
},
|
|
213
|
-
async search(...args) {
|
|
214
|
-
return (await server).search(...args);
|
|
215
|
-
},
|
|
216
|
-
async staticGET(...args) {
|
|
217
|
-
return (await server).staticGET(...args);
|
|
226
|
+
return createSearchAPI("advanced", {
|
|
227
|
+
...options,
|
|
228
|
+
indexes: async () => {
|
|
229
|
+
const indexes = source.getPages().map((page) => buildIndex(page));
|
|
230
|
+
return Promise.all(indexes);
|
|
218
231
|
}
|
|
219
|
-
};
|
|
232
|
+
});
|
|
220
233
|
}
|
|
221
234
|
|
|
222
235
|
// src/search/orama/_stemmers.ts
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { d as PageTree } from '../definitions-Q95-psoo.js';
|
|
|
4
4
|
import { Metadata } from 'next';
|
|
5
5
|
import { NextRequest } from 'next/server';
|
|
6
6
|
import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
|
|
7
|
-
export {
|
|
7
|
+
export { SortedResult } from '../search/index.js';
|
|
8
8
|
import 'react';
|
|
9
9
|
import 'unified';
|
|
10
10
|
import 'vfile';
|
|
@@ -34,6 +34,14 @@ declare function separatePageTree(pageTree: Root): Root[];
|
|
|
34
34
|
* Get other page tree nodes that lives under the same parent
|
|
35
35
|
*/
|
|
36
36
|
declare function getPageTreePeers(tree: Root, url: string): Item[];
|
|
37
|
+
/**
|
|
38
|
+
* Search the path of a node in the tree matched by the matcher.
|
|
39
|
+
*
|
|
40
|
+
* @returns The path to the target node (from starting root), or null if the page doesn't exist
|
|
41
|
+
*/
|
|
42
|
+
declare function findPath(nodes: Node[], matcher: (node: Node) => boolean, options?: {
|
|
43
|
+
includeSeparator?: boolean;
|
|
44
|
+
}): Node[] | null;
|
|
37
45
|
|
|
38
46
|
interface GetGithubLastCommitOptions {
|
|
39
47
|
/**
|
|
@@ -116,4 +124,4 @@ declare function createMetadataImage<S extends LoaderOutput<LoaderConfig>>(optio
|
|
|
116
124
|
}) => Response | Promise<Response>) => (request: NextRequest, options: any) => Response | Promise<Response>;
|
|
117
125
|
};
|
|
118
126
|
|
|
119
|
-
export { type GetGithubLastCommitOptions, createMetadataImage, findNeighbour, flattenTree, getGithubLastEdit, getPageTreePeers, getPageTreeRoots, separatePageTree };
|
|
127
|
+
export { type GetGithubLastCommitOptions, createMetadataImage, findNeighbour, findPath, flattenTree, getGithubLastEdit, getPageTreePeers, getPageTreeRoots, separatePageTree };
|
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
remarkHeading
|
|
3
3
|
} from "../chunk-QMATWJ5F.js";
|
|
4
|
+
import {
|
|
5
|
+
findNeighbour,
|
|
6
|
+
findPath,
|
|
7
|
+
flattenTree,
|
|
8
|
+
getPageTreePeers,
|
|
9
|
+
getPageTreeRoots,
|
|
10
|
+
separatePageTree
|
|
11
|
+
} from "../chunk-HV3YIUWE.js";
|
|
4
12
|
import "../chunk-JSBRDJBE.js";
|
|
5
13
|
|
|
6
14
|
// src/server/get-toc.ts
|
|
@@ -17,79 +25,6 @@ function getTableOfContents(content, remarkPlugins) {
|
|
|
17
25
|
return [];
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
// src/utils/page-tree.tsx
|
|
21
|
-
function flattenTree(nodes) {
|
|
22
|
-
const out = [];
|
|
23
|
-
for (const node of nodes) {
|
|
24
|
-
if (node.type === "folder") {
|
|
25
|
-
if (node.index) out.push(node.index);
|
|
26
|
-
out.push(...flattenTree(node.children));
|
|
27
|
-
} else if (node.type === "page") {
|
|
28
|
-
out.push(node);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
function findNeighbour(tree, url, options) {
|
|
34
|
-
const { separateRoot = true } = options ?? {};
|
|
35
|
-
const roots = separateRoot ? getPageTreeRoots(tree) : [tree];
|
|
36
|
-
if (tree.fallback) roots.push(tree.fallback);
|
|
37
|
-
for (const root of roots) {
|
|
38
|
-
const list = flattenTree(root.children);
|
|
39
|
-
const idx = list.findIndex((item) => item.url === url);
|
|
40
|
-
if (idx === -1) continue;
|
|
41
|
-
return {
|
|
42
|
-
previous: list[idx - 1],
|
|
43
|
-
next: list[idx + 1]
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
function getPageTreeRoots(pageTree) {
|
|
49
|
-
const result = pageTree.children.flatMap((child) => {
|
|
50
|
-
if (child.type !== "folder") return [];
|
|
51
|
-
const roots = getPageTreeRoots(child);
|
|
52
|
-
if (child.root) roots.push(child);
|
|
53
|
-
return roots;
|
|
54
|
-
});
|
|
55
|
-
if (!("type" in pageTree)) result.push(pageTree);
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
function separatePageTree(pageTree) {
|
|
59
|
-
return pageTree.children.flatMap((child) => {
|
|
60
|
-
if (child.type !== "folder") return [];
|
|
61
|
-
return {
|
|
62
|
-
name: child.name,
|
|
63
|
-
url: child.index?.url,
|
|
64
|
-
children: child.children
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function getPageTreePeers(tree, url) {
|
|
69
|
-
const parent = findParentFromTree(tree, url);
|
|
70
|
-
if (!parent) return [];
|
|
71
|
-
return parent.children.filter(
|
|
72
|
-
(item) => item.type === "page" && item.url !== url
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
function findParentFromTree(node, url) {
|
|
76
|
-
if ("index" in node && node.index?.url === url) {
|
|
77
|
-
return node;
|
|
78
|
-
}
|
|
79
|
-
for (const child of node.children) {
|
|
80
|
-
if (child.type === "folder") {
|
|
81
|
-
const parent = findParentFromTree(child, url);
|
|
82
|
-
if (parent) return parent;
|
|
83
|
-
}
|
|
84
|
-
if (child.type === "page" && child.url === url) {
|
|
85
|
-
return node;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if ("fallback" in node && node.fallback) {
|
|
89
|
-
return findParentFromTree(node.fallback, url);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
28
|
// src/source/page-tree/definitions.ts
|
|
94
29
|
var definitions_exports = {};
|
|
95
30
|
|
|
@@ -194,6 +129,7 @@ export {
|
|
|
194
129
|
definitions_exports as PageTree,
|
|
195
130
|
createMetadataImage,
|
|
196
131
|
findNeighbour,
|
|
132
|
+
findPath,
|
|
197
133
|
flattenTree,
|
|
198
134
|
getGithubLastEdit,
|
|
199
135
|
getPageTreePeers,
|
package/dist/source/index.d.ts
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
interface FileInfo {
|
|
6
|
+
/**
|
|
7
|
+
* File path without extension
|
|
8
|
+
*
|
|
9
|
+
* @deprecated obtain it with `join(dirname, name)`
|
|
10
|
+
*/
|
|
11
|
+
flattenedPath: string;
|
|
12
|
+
/**
|
|
13
|
+
* path of file (unparsed)
|
|
14
|
+
*/
|
|
15
|
+
path: string;
|
|
16
|
+
/**
|
|
17
|
+
* File name without extension
|
|
18
|
+
*/
|
|
19
|
+
name: string;
|
|
20
|
+
/**
|
|
21
|
+
* file extension from the last `.`, like `.md`
|
|
22
|
+
*
|
|
23
|
+
* empty string if no file extension
|
|
24
|
+
*/
|
|
25
|
+
ext: string;
|
|
26
|
+
dirname: string;
|
|
27
|
+
}
|
|
28
|
+
interface FolderInfo {
|
|
29
|
+
/**
|
|
30
|
+
* Original path of folder
|
|
31
|
+
*/
|
|
32
|
+
path: string;
|
|
33
|
+
/**
|
|
34
|
+
* folder name
|
|
35
|
+
*/
|
|
36
|
+
name: string;
|
|
37
|
+
dirname: string;
|
|
38
|
+
}
|
|
39
|
+
declare function parseFilePath(path: string): FileInfo;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated use `dirname` and `basename` directly.
|
|
42
|
+
*/
|
|
43
|
+
declare function parseFolderPath(path: string): FolderInfo;
|
|
4
44
|
|
|
5
45
|
/**
|
|
6
46
|
* In memory file system.
|
|
@@ -22,8 +62,8 @@ declare class FileSystem<File> {
|
|
|
22
62
|
}
|
|
23
63
|
|
|
24
64
|
interface LoadOptions {
|
|
25
|
-
transformers?: Transformer[];
|
|
26
65
|
buildFile: (file: VirtualFile) => MetaFile | PageFile;
|
|
66
|
+
plugins?: LoaderPlugin[];
|
|
27
67
|
}
|
|
28
68
|
type ContentStorage<Page extends PageData = PageData, Meta extends MetaData = MetaData> = FileSystem<MetaFile<Meta> | PageFile<Page>>;
|
|
29
69
|
interface MetaFile<Data extends MetaData = MetaData> {
|
|
@@ -41,7 +81,6 @@ interface PageFile<Data extends PageData = PageData> {
|
|
|
41
81
|
}
|
|
42
82
|
type Transformer = (context: {
|
|
43
83
|
storage: ContentStorage;
|
|
44
|
-
options: LoadOptions;
|
|
45
84
|
}) => void;
|
|
46
85
|
/**
|
|
47
86
|
* @returns a map of locale and its content storage.
|
|
@@ -50,45 +89,49 @@ type Transformer = (context: {
|
|
|
50
89
|
*/
|
|
51
90
|
declare function loadFiles(files: VirtualFile[], options: LoadOptions, i18n: I18nConfig): Record<string, ContentStorage>;
|
|
52
91
|
|
|
53
|
-
|
|
92
|
+
type LoaderPlugins<Page extends PageData, Meta extends MetaData> = LoaderPlugin<Page, Meta>[];
|
|
93
|
+
interface LoaderPlugin<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
|
|
54
94
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @deprecated obtain it with `join(dirname, name)`
|
|
95
|
+
* transform the storage after loading
|
|
58
96
|
*/
|
|
59
|
-
|
|
97
|
+
transformStorage?: (context: {
|
|
98
|
+
storage: ContentStorage<Page, Meta>;
|
|
99
|
+
}) => void;
|
|
60
100
|
/**
|
|
61
|
-
*
|
|
101
|
+
* transform the generated page tree
|
|
62
102
|
*/
|
|
63
|
-
|
|
103
|
+
transformPageTree?: PageTreeTransformer<Page, Meta>;
|
|
104
|
+
}
|
|
105
|
+
declare function buildPlugins<Page extends PageData, Meta extends MetaData>(plugins: LoaderPlugins<Page, Meta>): LoaderPlugin<Page, Meta>[];
|
|
106
|
+
|
|
107
|
+
interface LegacyLoaderOptions {
|
|
64
108
|
/**
|
|
65
|
-
*
|
|
109
|
+
* We recommend you to use `plugins` instead
|
|
66
110
|
*/
|
|
67
|
-
|
|
111
|
+
transformers?: Transformer[];
|
|
112
|
+
}
|
|
113
|
+
interface LegacyPageTreeOptions<Page extends PageData, Meta extends MetaData> {
|
|
68
114
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* empty string if no file extension
|
|
115
|
+
* @deprecated use `plugins` instead
|
|
72
116
|
*/
|
|
73
|
-
|
|
74
|
-
dirname: string;
|
|
75
|
-
}
|
|
76
|
-
interface FolderInfo {
|
|
117
|
+
attachFile?: (node: Item, file?: PageFile<Page>) => Item;
|
|
77
118
|
/**
|
|
78
|
-
*
|
|
119
|
+
* @deprecated use `plugins` instead
|
|
79
120
|
*/
|
|
80
|
-
|
|
121
|
+
attachFolder?: (node: Folder, folder: {
|
|
122
|
+
children: (PageFile<Page> | MetaFile<Meta>)[];
|
|
123
|
+
}, meta?: MetaFile<Meta>) => Folder;
|
|
81
124
|
/**
|
|
82
|
-
*
|
|
125
|
+
* @deprecated use `plugins` instead
|
|
83
126
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
127
|
+
attachSeparator?: (node: Separator) => Separator;
|
|
128
|
+
/**
|
|
129
|
+
* We recommend you to use `plugins` instead
|
|
130
|
+
*/
|
|
131
|
+
transformers?: PageTreeTransformer<Page, Meta>[];
|
|
86
132
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* @deprecated use `dirname` and `basename` directly.
|
|
90
|
-
*/
|
|
91
|
-
declare function parseFolderPath(path: string): FolderInfo;
|
|
133
|
+
|
|
134
|
+
type IconResolver = (icon: string | undefined) => ReactNode;
|
|
92
135
|
|
|
93
136
|
interface LoaderConfig {
|
|
94
137
|
source: SourceConfig;
|
|
@@ -98,21 +141,23 @@ interface SourceConfig {
|
|
|
98
141
|
pageData: PageData;
|
|
99
142
|
metaData: MetaData;
|
|
100
143
|
}
|
|
101
|
-
|
|
144
|
+
type LoaderOptions<Config extends SourceConfig = SourceConfig, I18n extends I18nConfig | undefined = I18nConfig | undefined> = BaseLoaderOptions<NoInfer<Config>> & {
|
|
145
|
+
source: Source<Config> | Source<Config>[];
|
|
146
|
+
/**
|
|
147
|
+
* Configure i18n
|
|
148
|
+
*/
|
|
149
|
+
i18n?: I18n;
|
|
150
|
+
};
|
|
151
|
+
interface BaseLoaderOptions<Config extends SourceConfig> extends LegacyLoaderOptions {
|
|
102
152
|
baseUrl: string;
|
|
103
|
-
icon?:
|
|
153
|
+
icon?: IconResolver;
|
|
104
154
|
slugs?: (info: FileInfo) => string[];
|
|
105
155
|
url?: UrlFn;
|
|
106
|
-
source: Source<T> | Source<T>[];
|
|
107
|
-
transformers?: Transformer[];
|
|
108
156
|
/**
|
|
109
157
|
* Additional options for page tree builder
|
|
110
158
|
*/
|
|
111
|
-
pageTree?: Partial<BaseOptions<
|
|
112
|
-
|
|
113
|
-
* Configure i18n
|
|
114
|
-
*/
|
|
115
|
-
i18n?: I18n;
|
|
159
|
+
pageTree?: Partial<BaseOptions> & LegacyPageTreeOptions<Config['pageData'], Config['metaData']>;
|
|
160
|
+
plugins?: LoaderPlugins<Config['pageData'], Config['metaData']>;
|
|
116
161
|
}
|
|
117
162
|
interface Source<Config extends SourceConfig> {
|
|
118
163
|
/**
|
|
@@ -183,13 +228,19 @@ interface LoaderOutput<Config extends LoaderConfig> {
|
|
|
183
228
|
page: Page<Config['source']['pageData']>;
|
|
184
229
|
hash?: string;
|
|
185
230
|
} | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
186
234
|
_i18n?: I18nConfig;
|
|
187
235
|
/**
|
|
188
|
-
* Get list of pages from language
|
|
236
|
+
* Get a list of pages from specified language
|
|
189
237
|
*
|
|
190
|
-
* @param language - If empty,
|
|
238
|
+
* @param language - If empty, list pages from all languages.
|
|
191
239
|
*/
|
|
192
240
|
getPages: (language?: string) => Page<Config['source']['pageData']>[];
|
|
241
|
+
/**
|
|
242
|
+
* get each language and its pages, empty if i18n is not enabled.
|
|
243
|
+
*/
|
|
193
244
|
getLanguages: () => LanguageEntry<Config['source']['pageData']>[];
|
|
194
245
|
/**
|
|
195
246
|
* Get page with slugs
|
|
@@ -237,53 +288,36 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
|
|
|
237
288
|
*/
|
|
238
289
|
type UrlFn = (slugs: string[], locale?: string) => string;
|
|
239
290
|
|
|
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;
|
|
251
|
-
/**
|
|
252
|
-
* @deprecated use `transformers` instead
|
|
253
|
-
*/
|
|
254
|
-
attachSeparator?: (node: Separator) => Separator;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
291
|
interface PageTreeBuilderContext<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
|
|
258
292
|
/**
|
|
259
293
|
* @internal resolve paths without extensions
|
|
260
294
|
*/
|
|
261
295
|
resolveName: (name: string, format: 'meta' | 'page') => string;
|
|
262
|
-
options: BaseOptions
|
|
296
|
+
options: BaseOptions;
|
|
263
297
|
transformers: PageTreeTransformer<Page, Meta>[];
|
|
264
|
-
builder: PageTreeBuilder
|
|
298
|
+
builder: PageTreeBuilder;
|
|
265
299
|
storage: ContentStorage<Page, Meta>;
|
|
266
300
|
getUrl: UrlFn;
|
|
267
301
|
storages?: Record<string, ContentStorage<Page, Meta>>;
|
|
268
302
|
locale?: string;
|
|
269
303
|
visitedPaths: Set<string>;
|
|
270
304
|
}
|
|
271
|
-
interface PageTreeTransformer<Page extends PageData =
|
|
305
|
+
interface PageTreeTransformer<Page extends PageData = PageData, Meta extends MetaData = MetaData> {
|
|
272
306
|
name?: string;
|
|
273
307
|
file?: (this: PageTreeBuilderContext<Page, Meta>, node: Item, filePath?: string) => Item;
|
|
274
308
|
folder?: (this: PageTreeBuilderContext<Page, Meta>, node: Folder, folderPath: string, metaPath?: string) => Folder;
|
|
275
309
|
separator?: (this: PageTreeBuilderContext<Page, Meta>, node: Separator) => Separator;
|
|
276
310
|
root?: (this: PageTreeBuilderContext<Page, Meta>, node: Root) => Root;
|
|
277
311
|
}
|
|
278
|
-
interface BaseOptions
|
|
312
|
+
interface BaseOptions {
|
|
313
|
+
id?: string;
|
|
279
314
|
/**
|
|
280
315
|
* Remove references to the file path of original nodes (`$ref`)
|
|
281
316
|
*
|
|
282
317
|
* @defaultValue false
|
|
283
318
|
*/
|
|
284
319
|
noRef?: boolean;
|
|
285
|
-
|
|
286
|
-
resolveIcon?: (icon: string | undefined) => ReactNode | undefined;
|
|
320
|
+
plugins?: LoaderPlugin[];
|
|
287
321
|
/**
|
|
288
322
|
* generate fallback page tree
|
|
289
323
|
*
|
|
@@ -291,19 +325,17 @@ interface BaseOptions<Page extends PageData = PageData, Meta extends MetaData =
|
|
|
291
325
|
*/
|
|
292
326
|
generateFallback?: boolean;
|
|
293
327
|
}
|
|
294
|
-
interface PageTreeBuilder
|
|
295
|
-
build: (options: BaseOptions
|
|
296
|
-
|
|
297
|
-
storage: ContentStorage<Page, Meta>;
|
|
328
|
+
interface PageTreeBuilder {
|
|
329
|
+
build: (options: BaseOptions & {
|
|
330
|
+
storage: ContentStorage;
|
|
298
331
|
}) => Root;
|
|
299
332
|
/**
|
|
300
333
|
* Build page tree and fallback to the default language if the localized page doesn't exist
|
|
301
334
|
*/
|
|
302
|
-
buildI18n: (options: BaseOptions
|
|
303
|
-
|
|
304
|
-
storages: Record<string, ContentStorage<Page, Meta>>;
|
|
335
|
+
buildI18n: (options: BaseOptions & {
|
|
336
|
+
storages: Record<string, ContentStorage>;
|
|
305
337
|
}) => Record<string, Root>;
|
|
306
338
|
}
|
|
307
339
|
declare function createPageTreeBuilder(getUrl: UrlFn): PageTreeBuilder;
|
|
308
340
|
|
|
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 };
|
|
341
|
+
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, parseFolderPath };
|