fumadocs-core 12.3.1 → 12.3.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.
- package/dist/dynamic-link.d.ts +1 -1
- package/dist/link.d.ts +1 -1
- package/dist/search/server.d.ts +8 -4
- package/dist/search/server.js +121 -106
- package/package.json +7 -7
package/dist/dynamic-link.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type DynamicLinkProps = LinkProps;
|
|
|
8
8
|
* It supports dynamic hrefs, which means you can use `/[lang]/my-page` with `dynamicHrefs` enabled
|
|
9
9
|
*/
|
|
10
10
|
declare const DynamicLink: react.ForwardRefExoticComponent<react.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
11
|
-
external?: boolean
|
|
11
|
+
external?: boolean;
|
|
12
12
|
} & react.RefAttributes<HTMLAnchorElement>>;
|
|
13
13
|
|
|
14
14
|
export { DynamicLink, type DynamicLinkProps, DynamicLink as default };
|
package/dist/link.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare const Link: react.ForwardRefExoticComponent<AnchorHTMLAttributes<HTMLAnc
|
|
|
18
18
|
*
|
|
19
19
|
* automatically determined by default
|
|
20
20
|
*/
|
|
21
|
-
external?: boolean
|
|
21
|
+
external?: boolean;
|
|
22
22
|
} & react.RefAttributes<HTMLAnchorElement>>;
|
|
23
23
|
|
|
24
24
|
export { type LinkProps, Link as default };
|
package/dist/search/server.d.ts
CHANGED
|
@@ -5,18 +5,22 @@ import 'mdast';
|
|
|
5
5
|
import 'unified';
|
|
6
6
|
|
|
7
7
|
interface SearchAPI {
|
|
8
|
-
GET: (request: NextRequest) => NextResponse<SortedResult[]
|
|
8
|
+
GET: (request: NextRequest) => Promise<NextResponse<SortedResult[]>>;
|
|
9
9
|
search: (query: string, options?: {
|
|
10
10
|
locale?: string;
|
|
11
11
|
tag?: string;
|
|
12
|
-
}) => SortedResult[]
|
|
12
|
+
}) => Promise<SortedResult[]>;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve indexes dynamically
|
|
16
|
+
*/
|
|
17
|
+
type Dynamic<T> = () => T[] | Promise<T[]>;
|
|
14
18
|
interface SimpleOptions {
|
|
15
|
-
indexes: Index[]
|
|
19
|
+
indexes: Index[] | Dynamic<Index>;
|
|
16
20
|
language?: string;
|
|
17
21
|
}
|
|
18
22
|
interface AdvancedOptions {
|
|
19
|
-
indexes: AdvancedIndex[]
|
|
23
|
+
indexes: AdvancedIndex[] | Dynamic<AdvancedIndex>;
|
|
20
24
|
/**
|
|
21
25
|
* Enabled custom tags
|
|
22
26
|
*/
|
package/dist/search/server.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
__async,
|
|
2
3
|
__spreadProps,
|
|
3
4
|
__spreadValues
|
|
4
5
|
} from "../chunk-CWMXXUWU.js";
|
|
@@ -10,15 +11,17 @@ function create(search) {
|
|
|
10
11
|
return {
|
|
11
12
|
search,
|
|
12
13
|
GET(request) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
return __async(this, null, function* () {
|
|
15
|
+
var _a2, _b;
|
|
16
|
+
const query = request.nextUrl.searchParams.get("query");
|
|
17
|
+
if (!query) return NextResponse.json([]);
|
|
18
|
+
return NextResponse.json(
|
|
19
|
+
yield search(query, {
|
|
20
|
+
tag: (_a2 = request.nextUrl.searchParams.get("tag")) != null ? _a2 : void 0,
|
|
21
|
+
locale: (_b = request.nextUrl.searchParams.get("locale")) != null ? _b : void 0
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
};
|
|
24
27
|
}
|
|
@@ -34,62 +37,69 @@ function createI18nSearchAPI(type, options) {
|
|
|
34
37
|
const v = Array.isArray(entry) ? { language: entry[0], indexes: entry[1] } : entry;
|
|
35
38
|
map.set(
|
|
36
39
|
v.language,
|
|
40
|
+
// @ts-expect-error -- Index depends on generic types
|
|
37
41
|
createSearchAPI(type, __spreadProps(__spreadValues({}, options), {
|
|
38
42
|
language: v.language,
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment -- Avoid complicated types
|
|
40
43
|
indexes: v.indexes
|
|
41
44
|
}))
|
|
42
45
|
);
|
|
43
46
|
}
|
|
44
|
-
return create((query, searchOptions) => {
|
|
47
|
+
return create((query, searchOptions) => __async(this, null, function* () {
|
|
45
48
|
if (searchOptions == null ? void 0 : searchOptions.locale) {
|
|
46
49
|
const handler = map.get(searchOptions.locale);
|
|
47
50
|
if (handler) return handler.search(query, searchOptions);
|
|
48
51
|
}
|
|
49
52
|
return [];
|
|
50
|
-
});
|
|
53
|
+
}));
|
|
51
54
|
}
|
|
52
55
|
function initSearchAPI({ indexes, language }) {
|
|
53
56
|
const store = ["title", "url"];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
function getDocument() {
|
|
58
|
+
return __async(this, null, function* () {
|
|
59
|
+
const items = typeof indexes === "function" ? yield indexes() : indexes;
|
|
60
|
+
const index = new Document({
|
|
61
|
+
language,
|
|
62
|
+
optimize: true,
|
|
63
|
+
cache: 100,
|
|
64
|
+
document: {
|
|
65
|
+
id: "url",
|
|
66
|
+
store,
|
|
67
|
+
index: [
|
|
68
|
+
{
|
|
69
|
+
field: "title",
|
|
70
|
+
tokenize: "forward",
|
|
71
|
+
resolution: 9
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
field: "content",
|
|
75
|
+
tokenize: "strict",
|
|
76
|
+
context: {
|
|
77
|
+
depth: 1,
|
|
78
|
+
resolution: 9
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
field: "keywords",
|
|
83
|
+
tokenize: "strict",
|
|
84
|
+
resolution: 9
|
|
85
|
+
}
|
|
86
|
+
]
|
|
79
87
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
});
|
|
89
|
+
for (const page of items) {
|
|
90
|
+
index.add({
|
|
91
|
+
title: page.title,
|
|
92
|
+
url: page.url,
|
|
93
|
+
content: page.content,
|
|
94
|
+
keywords: page.keywords
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return index;
|
|
89
98
|
});
|
|
90
99
|
}
|
|
91
|
-
|
|
92
|
-
|
|
100
|
+
const doc = getDocument();
|
|
101
|
+
return create((query) => __async(this, null, function* () {
|
|
102
|
+
const results = (yield doc).search(query, 5, {
|
|
93
103
|
enrich: true,
|
|
94
104
|
suggest: true
|
|
95
105
|
});
|
|
@@ -100,7 +110,7 @@ function initSearchAPI({ indexes, language }) {
|
|
|
100
110
|
id: page.doc.url,
|
|
101
111
|
url: page.doc.url
|
|
102
112
|
}));
|
|
103
|
-
});
|
|
113
|
+
}));
|
|
104
114
|
}
|
|
105
115
|
function initSearchAPIAdvanced({
|
|
106
116
|
indexes,
|
|
@@ -108,64 +118,71 @@ function initSearchAPIAdvanced({
|
|
|
108
118
|
tag = false
|
|
109
119
|
}) {
|
|
110
120
|
const store = ["id", "url", "content", "page_id", "type"];
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let id = 0;
|
|
131
|
-
index.add({
|
|
132
|
-
id: page.id,
|
|
133
|
-
page_id: page.id,
|
|
134
|
-
type: "page",
|
|
135
|
-
content: page.title,
|
|
136
|
-
tag: page.tag,
|
|
137
|
-
url: page.url
|
|
138
|
-
});
|
|
139
|
-
for (const heading of data.headings) {
|
|
140
|
-
index.add({
|
|
141
|
-
id: page.id + (id++).toString(),
|
|
142
|
-
page_id: page.id,
|
|
143
|
-
type: "heading",
|
|
144
|
-
tag: page.tag,
|
|
145
|
-
url: `${page.url}#${heading.id}`,
|
|
146
|
-
content: heading.content
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
for (const content of data.contents) {
|
|
150
|
-
index.add({
|
|
151
|
-
id: page.id + (id++).toString(),
|
|
152
|
-
page_id: page.id,
|
|
153
|
-
tag: page.tag,
|
|
154
|
-
type: "text",
|
|
155
|
-
url: content.heading ? `${page.url}#${content.heading}` : page.url,
|
|
156
|
-
content: content.content
|
|
121
|
+
function getDocument() {
|
|
122
|
+
return __async(this, null, function* () {
|
|
123
|
+
const items = typeof indexes === "function" ? yield indexes() : indexes;
|
|
124
|
+
const index = new Document({
|
|
125
|
+
language,
|
|
126
|
+
cache: 100,
|
|
127
|
+
tokenize: "forward",
|
|
128
|
+
optimize: true,
|
|
129
|
+
context: {
|
|
130
|
+
depth: 2,
|
|
131
|
+
bidirectional: true,
|
|
132
|
+
resolution: 9
|
|
133
|
+
},
|
|
134
|
+
document: {
|
|
135
|
+
id: "id",
|
|
136
|
+
tag: tag ? "tag" : void 0,
|
|
137
|
+
store,
|
|
138
|
+
index: ["content"]
|
|
139
|
+
}
|
|
157
140
|
});
|
|
158
|
-
|
|
141
|
+
for (const page of items) {
|
|
142
|
+
const data = page.structuredData;
|
|
143
|
+
let id = 0;
|
|
144
|
+
index.add({
|
|
145
|
+
id: page.id,
|
|
146
|
+
page_id: page.id,
|
|
147
|
+
type: "page",
|
|
148
|
+
content: page.title,
|
|
149
|
+
tag: page.tag,
|
|
150
|
+
url: page.url
|
|
151
|
+
});
|
|
152
|
+
for (const heading of data.headings) {
|
|
153
|
+
index.add({
|
|
154
|
+
id: page.id + (id++).toString(),
|
|
155
|
+
page_id: page.id,
|
|
156
|
+
type: "heading",
|
|
157
|
+
tag: page.tag,
|
|
158
|
+
url: `${page.url}#${heading.id}`,
|
|
159
|
+
content: heading.content
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
for (const content of data.contents) {
|
|
163
|
+
index.add({
|
|
164
|
+
id: page.id + (id++).toString(),
|
|
165
|
+
page_id: page.id,
|
|
166
|
+
tag: page.tag,
|
|
167
|
+
type: "text",
|
|
168
|
+
url: content.heading ? `${page.url}#${content.heading}` : page.url,
|
|
169
|
+
content: content.content
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return index;
|
|
174
|
+
});
|
|
159
175
|
}
|
|
160
|
-
|
|
176
|
+
const doc = getDocument();
|
|
177
|
+
return create((query, options) => __async(this, null, function* () {
|
|
161
178
|
var _a, _b, _c;
|
|
179
|
+
const index = yield doc;
|
|
162
180
|
const results = index.search(query, 5, {
|
|
163
181
|
enrich: true,
|
|
164
182
|
tag: options == null ? void 0 : options.tag,
|
|
165
183
|
limit: 6
|
|
166
184
|
});
|
|
167
185
|
const map = /* @__PURE__ */ new Map();
|
|
168
|
-
const sortedResult = [];
|
|
169
186
|
for (const item of (_b = (_a = results[0]) == null ? void 0 : _a.result) != null ? _b : []) {
|
|
170
187
|
if (item.doc.type === "page") {
|
|
171
188
|
if (!map.has(item.doc.page_id)) {
|
|
@@ -173,18 +190,16 @@ function initSearchAPIAdvanced({
|
|
|
173
190
|
}
|
|
174
191
|
continue;
|
|
175
192
|
}
|
|
176
|
-
const
|
|
193
|
+
const list = (_c = map.get(item.doc.page_id)) != null ? _c : [];
|
|
194
|
+
list.push({
|
|
177
195
|
id: item.doc.id,
|
|
178
196
|
content: item.doc.content,
|
|
179
197
|
type: item.doc.type,
|
|
180
198
|
url: item.doc.url
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
(_c = map.get(item.doc.page_id)) == null ? void 0 : _c.push(i);
|
|
184
|
-
} else {
|
|
185
|
-
map.set(item.doc.page_id, [i]);
|
|
186
|
-
}
|
|
199
|
+
});
|
|
200
|
+
map.set(item.doc.page_id, list);
|
|
187
201
|
}
|
|
202
|
+
const sortedResult = [];
|
|
188
203
|
for (const [id, items] of map.entries()) {
|
|
189
204
|
const page = index.get(id);
|
|
190
205
|
if (!page) continue;
|
|
@@ -197,7 +212,7 @@ function initSearchAPIAdvanced({
|
|
|
197
212
|
sortedResult.push(...items);
|
|
198
213
|
}
|
|
199
214
|
return sortedResult;
|
|
200
|
-
});
|
|
215
|
+
}));
|
|
201
216
|
}
|
|
202
217
|
export {
|
|
203
218
|
createI18nSearchAPI,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "12.3.
|
|
3
|
+
"version": "12.3.2",
|
|
4
4
|
"description": "The library for building a documentation website in Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -120,8 +120,8 @@
|
|
|
120
120
|
],
|
|
121
121
|
"dependencies": {
|
|
122
122
|
"@formatjs/intl-localematcher": "^0.5.4",
|
|
123
|
-
"@shikijs/rehype": "^1.
|
|
124
|
-
"@shikijs/transformers": "^1.
|
|
123
|
+
"@shikijs/rehype": "^1.10.0",
|
|
124
|
+
"@shikijs/transformers": "^1.10.0",
|
|
125
125
|
"flexsearch": "0.7.21",
|
|
126
126
|
"github-slugger": "^2.0.0",
|
|
127
127
|
"negotiator": "^0.6.3",
|
|
@@ -131,12 +131,12 @@
|
|
|
131
131
|
"remark-gfm": "^4.0.0",
|
|
132
132
|
"remark-mdx": "^3.0.1",
|
|
133
133
|
"scroll-into-view-if-needed": "^3.1.0",
|
|
134
|
-
"shiki": "^1.
|
|
134
|
+
"shiki": "^1.10.0",
|
|
135
135
|
"swr": "^2.2.5",
|
|
136
136
|
"unist-util-visit": "^5.0.0"
|
|
137
137
|
},
|
|
138
138
|
"devDependencies": {
|
|
139
|
-
"@algolia/client-search": "^4.
|
|
139
|
+
"@algolia/client-search": "^4.24.0",
|
|
140
140
|
"@mdx-js/mdx": "^3.0.1",
|
|
141
141
|
"@types/estree-jsx": "^1.0.5",
|
|
142
142
|
"@types/flexsearch": "0.7.6",
|
|
@@ -146,9 +146,9 @@
|
|
|
146
146
|
"@types/node": "18.17.5",
|
|
147
147
|
"@types/react": "^18.3.3",
|
|
148
148
|
"@types/react-dom": "^18.3.0",
|
|
149
|
-
"algoliasearch": "^4.
|
|
149
|
+
"algoliasearch": "^4.24.0",
|
|
150
150
|
"next": "^14.2.4",
|
|
151
|
-
"unified": "^11.0.
|
|
151
|
+
"unified": "^11.0.5",
|
|
152
152
|
"eslint-config-custom": "0.0.0",
|
|
153
153
|
"tsconfig": "0.0.0"
|
|
154
154
|
},
|