fumadocs-core 10.0.2 → 10.0.4
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/search/server.d.ts +5 -1
- package/dist/search/server.js +76 -75
- package/package.json +2 -2
package/dist/search/server.d.ts
CHANGED
|
@@ -5,7 +5,11 @@ import 'mdast';
|
|
|
5
5
|
import 'unified';
|
|
6
6
|
|
|
7
7
|
interface SearchAPI {
|
|
8
|
-
GET: (request: NextRequest) => NextResponse<SortedResult[]
|
|
8
|
+
GET: (request: NextRequest) => NextResponse<SortedResult[]>;
|
|
9
|
+
search: (query: string, options?: {
|
|
10
|
+
locale?: string;
|
|
11
|
+
tag?: string;
|
|
12
|
+
}) => SortedResult[];
|
|
9
13
|
}
|
|
10
14
|
interface SimpleOptions {
|
|
11
15
|
indexes: Index[];
|
package/dist/search/server.js
CHANGED
|
@@ -6,6 +6,23 @@ import {
|
|
|
6
6
|
// src/search/server.ts
|
|
7
7
|
import { Document } from "flexsearch";
|
|
8
8
|
import { NextResponse } from "next/server";
|
|
9
|
+
function create(search) {
|
|
10
|
+
return {
|
|
11
|
+
search,
|
|
12
|
+
GET(request) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const query = request.nextUrl.searchParams.get("query");
|
|
15
|
+
if (!query)
|
|
16
|
+
return NextResponse.json([]);
|
|
17
|
+
return NextResponse.json(
|
|
18
|
+
search(query, {
|
|
19
|
+
tag: (_a = request.nextUrl.searchParams.get("tag")) != null ? _a : void 0,
|
|
20
|
+
locale: (_b = request.nextUrl.searchParams.get("locale")) != null ? _b : void 0
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
9
26
|
function createSearchAPI(type, options) {
|
|
10
27
|
if (type === "simple") {
|
|
11
28
|
return initSearchAPI(options);
|
|
@@ -24,17 +41,14 @@ function createI18nSearchAPI(type, options) {
|
|
|
24
41
|
}))
|
|
25
42
|
);
|
|
26
43
|
}
|
|
27
|
-
return {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
if (handler)
|
|
33
|
-
return handler.GET(request);
|
|
34
|
-
}
|
|
35
|
-
return NextResponse.json([]);
|
|
44
|
+
return create((query, searchOptions) => {
|
|
45
|
+
if (searchOptions == null ? void 0 : searchOptions.locale) {
|
|
46
|
+
const handler = map.get(searchOptions.locale);
|
|
47
|
+
if (handler)
|
|
48
|
+
return handler.search(query, searchOptions);
|
|
36
49
|
}
|
|
37
|
-
|
|
50
|
+
return [];
|
|
51
|
+
});
|
|
38
52
|
}
|
|
39
53
|
function initSearchAPI({ indexes, language }) {
|
|
40
54
|
const store = ["title", "url"];
|
|
@@ -75,27 +89,20 @@ function initSearchAPI({ indexes, language }) {
|
|
|
75
89
|
keywords: page.keywords
|
|
76
90
|
});
|
|
77
91
|
}
|
|
78
|
-
return {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
content: page.doc.title,
|
|
93
|
-
id: page.doc.url,
|
|
94
|
-
url: page.doc.url
|
|
95
|
-
}));
|
|
96
|
-
return NextResponse.json(pages);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
92
|
+
return create((query) => {
|
|
93
|
+
const results = index.search(query, 5, {
|
|
94
|
+
enrich: true,
|
|
95
|
+
suggest: true
|
|
96
|
+
});
|
|
97
|
+
if (results.length === 0)
|
|
98
|
+
return [];
|
|
99
|
+
return results[0].result.map((page) => ({
|
|
100
|
+
type: "page",
|
|
101
|
+
content: page.doc.title,
|
|
102
|
+
id: page.doc.url,
|
|
103
|
+
url: page.doc.url
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
99
106
|
}
|
|
100
107
|
function initSearchAPIAdvanced({
|
|
101
108
|
indexes,
|
|
@@ -152,54 +159,48 @@ function initSearchAPIAdvanced({
|
|
|
152
159
|
});
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
|
-
return {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const sortedResult = [];
|
|
169
|
-
for (const item of (_b = (_a = results[0]) == null ? void 0 : _a.result) != null ? _b : []) {
|
|
170
|
-
if (item.doc.type === "page") {
|
|
171
|
-
if (!map.has(item.doc.page_id)) {
|
|
172
|
-
map.set(item.doc.page_id, []);
|
|
173
|
-
}
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
const i = {
|
|
177
|
-
id: item.doc.id,
|
|
178
|
-
content: item.doc.content,
|
|
179
|
-
type: item.doc.type,
|
|
180
|
-
url: item.doc.url
|
|
181
|
-
};
|
|
182
|
-
if (map.has(item.doc.page_id)) {
|
|
183
|
-
(_c = map.get(item.doc.page_id)) == null ? void 0 : _c.push(i);
|
|
184
|
-
} else {
|
|
185
|
-
map.set(item.doc.page_id, [i]);
|
|
162
|
+
return create((query, options) => {
|
|
163
|
+
var _a, _b, _c;
|
|
164
|
+
const results = index.search(query, 5, {
|
|
165
|
+
enrich: true,
|
|
166
|
+
tag: options == null ? void 0 : options.tag,
|
|
167
|
+
limit: 6
|
|
168
|
+
});
|
|
169
|
+
const map = /* @__PURE__ */ new Map();
|
|
170
|
+
const sortedResult = [];
|
|
171
|
+
for (const item of (_b = (_a = results[0]) == null ? void 0 : _a.result) != null ? _b : []) {
|
|
172
|
+
if (item.doc.type === "page") {
|
|
173
|
+
if (!map.has(item.doc.page_id)) {
|
|
174
|
+
map.set(item.doc.page_id, []);
|
|
186
175
|
}
|
|
176
|
+
continue;
|
|
187
177
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
sortedResult.push(...items);
|
|
178
|
+
const i = {
|
|
179
|
+
id: item.doc.id,
|
|
180
|
+
content: item.doc.content,
|
|
181
|
+
type: item.doc.type,
|
|
182
|
+
url: item.doc.url
|
|
183
|
+
};
|
|
184
|
+
if (map.has(item.doc.page_id)) {
|
|
185
|
+
(_c = map.get(item.doc.page_id)) == null ? void 0 : _c.push(i);
|
|
186
|
+
} else {
|
|
187
|
+
map.set(item.doc.page_id, [i]);
|
|
199
188
|
}
|
|
200
|
-
return NextResponse.json(sortedResult);
|
|
201
189
|
}
|
|
202
|
-
|
|
190
|
+
for (const [id, items] of map.entries()) {
|
|
191
|
+
const page = index.get(id);
|
|
192
|
+
if (!page)
|
|
193
|
+
continue;
|
|
194
|
+
sortedResult.push({
|
|
195
|
+
id: page.id,
|
|
196
|
+
content: page.content,
|
|
197
|
+
type: "page",
|
|
198
|
+
url: page.url
|
|
199
|
+
});
|
|
200
|
+
sortedResult.push(...items);
|
|
201
|
+
}
|
|
202
|
+
return sortedResult;
|
|
203
|
+
});
|
|
203
204
|
}
|
|
204
205
|
export {
|
|
205
206
|
createI18nSearchAPI,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.4",
|
|
4
4
|
"description": "The library for building a documentation website in Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"@formatjs/intl-localematcher": "^0.5.4",
|
|
112
112
|
"@shikijs/rehype": "^1.1.7",
|
|
113
113
|
"@shikijs/transformers": "^1.1.7",
|
|
114
|
-
"flexsearch": "
|
|
114
|
+
"flexsearch": "0.7.21",
|
|
115
115
|
"github-slugger": "^2.0.0",
|
|
116
116
|
"hast-util-to-estree": "^3.1.0",
|
|
117
117
|
"negotiator": "^0.6.3",
|