fumadocs-core 12.5.3 → 12.5.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/breadcrumb.js +5 -9
- package/dist/chunk-DVOZJZGH.js +42 -0
- package/dist/chunk-KGMG4N3Y.js +13 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/{chunk-EP2HYVJS.js → chunk-V6DBK6TW.js} +1 -1
- package/dist/{chunk-QRNTLL6S.js → chunk-YKIM647L.js} +5 -6
- package/dist/dynamic-link.js +5 -9
- package/dist/link.js +2 -2
- package/dist/mdx-plugins/index.js +24 -20
- package/dist/middleware.js +1 -1
- package/dist/search/client.js +10 -14
- package/dist/search/server.js +113 -124
- package/dist/search-algolia/client.js +18 -23
- package/dist/search-algolia/server.js +29 -36
- package/dist/server/index.js +39 -48
- package/dist/sidebar.js +22 -31
- package/dist/source/index.js +51 -52
- package/dist/toc-internal.js +12 -26
- package/dist/toc.js +6 -12
- package/dist/utils/use-on-change.d.ts +3 -0
- package/dist/utils/use-on-change.js +7 -0
- package/package.json +9 -2
- package/dist/chunk-CWMXXUWU.js +0 -63
- package/dist/chunk-UMTVJNLA.js +0 -52
package/dist/breadcrumb.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
__objRest
|
|
3
|
-
} from "./chunk-CWMXXUWU.js";
|
|
1
|
+
import "./chunk-MLKGABMK.js";
|
|
4
2
|
|
|
5
3
|
// src/breadcrumb.tsx
|
|
6
4
|
import { useMemo } from "react";
|
|
@@ -11,9 +9,8 @@ function useBreadcrumb(url, tree, options) {
|
|
|
11
9
|
);
|
|
12
10
|
}
|
|
13
11
|
function getBreadcrumbItems(url, tree, options = {}) {
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const path = (_b = searchPath(tree.children, url, rest)) != null ? _b : [];
|
|
12
|
+
const { includeRoot, ...rest } = options;
|
|
13
|
+
const path = searchPath(tree.children, url, rest) ?? [];
|
|
17
14
|
if (includeRoot) {
|
|
18
15
|
path.unshift({
|
|
19
16
|
name: tree.name,
|
|
@@ -23,13 +20,12 @@ function getBreadcrumbItems(url, tree, options = {}) {
|
|
|
23
20
|
return path;
|
|
24
21
|
}
|
|
25
22
|
function searchPath(nodes, url, options) {
|
|
26
|
-
var _a, _b;
|
|
27
23
|
const { includePage = true, includeSeparator = false } = options;
|
|
28
24
|
let separator;
|
|
29
25
|
for (const node of nodes) {
|
|
30
26
|
if (includeSeparator && node.type === "separator") separator = node.name;
|
|
31
27
|
if (node.type === "folder") {
|
|
32
|
-
if (
|
|
28
|
+
if (node.index?.url === url) {
|
|
33
29
|
const items2 = [];
|
|
34
30
|
if (separator) items2.push({ name: separator });
|
|
35
31
|
if (options.includePage)
|
|
@@ -43,7 +39,7 @@ function searchPath(nodes, url, options) {
|
|
|
43
39
|
if (items) {
|
|
44
40
|
items.unshift({
|
|
45
41
|
name: node.name,
|
|
46
|
-
url:
|
|
42
|
+
url: node.index?.url
|
|
47
43
|
});
|
|
48
44
|
if (separator) items.unshift({ name: separator });
|
|
49
45
|
return items;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/link.tsx
|
|
2
|
+
import Original from "next/link";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var Link = forwardRef(
|
|
6
|
+
({
|
|
7
|
+
href = "#",
|
|
8
|
+
external = !(href.startsWith("/") || href.startsWith("#") || href.startsWith(".")),
|
|
9
|
+
prefetch,
|
|
10
|
+
replace,
|
|
11
|
+
...props
|
|
12
|
+
}, ref) => {
|
|
13
|
+
if (external) {
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
"a",
|
|
16
|
+
{
|
|
17
|
+
ref,
|
|
18
|
+
href,
|
|
19
|
+
rel: "noreferrer noopener",
|
|
20
|
+
target: "_blank",
|
|
21
|
+
...props,
|
|
22
|
+
children: props.children
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
Original,
|
|
28
|
+
{
|
|
29
|
+
ref,
|
|
30
|
+
href,
|
|
31
|
+
prefetch,
|
|
32
|
+
replace,
|
|
33
|
+
...props
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
Link.displayName = "Link";
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
Link
|
|
42
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/utils/use-on-change.ts
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
function useOnChange(value, onChange) {
|
|
4
|
+
const [prev, setPrev] = useState(value);
|
|
5
|
+
if (prev !== value) {
|
|
6
|
+
onChange(value, prev);
|
|
7
|
+
setPrev(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
useOnChange
|
|
13
|
+
};
|
|
@@ -12,7 +12,7 @@ function flattenNode(node) {
|
|
|
12
12
|
|
|
13
13
|
// src/mdx-plugins/remark-heading.ts
|
|
14
14
|
var slugger = new Slugger();
|
|
15
|
-
var regex =
|
|
15
|
+
var regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
|
|
16
16
|
function remarkHeading({
|
|
17
17
|
slug: defaultSlug,
|
|
18
18
|
customId = true
|
|
@@ -21,13 +21,12 @@ function remarkHeading({
|
|
|
21
21
|
const toc = [];
|
|
22
22
|
slugger.reset();
|
|
23
23
|
visit(root, "heading", (heading) => {
|
|
24
|
-
|
|
25
|
-
heading.data
|
|
26
|
-
(_a = heading.data).hProperties || (_a.hProperties = {});
|
|
24
|
+
heading.data ||= {};
|
|
25
|
+
heading.data.hProperties ||= {};
|
|
27
26
|
const lastNode = heading.children.at(-1);
|
|
28
|
-
if (!heading.data.hProperties.id &&
|
|
27
|
+
if (!heading.data.hProperties.id && lastNode?.type === "text" && customId) {
|
|
29
28
|
const match = regex.exec(lastNode.value);
|
|
30
|
-
if (match
|
|
29
|
+
if (match?.[1]) {
|
|
31
30
|
heading.data.hProperties.id = match[1];
|
|
32
31
|
lastNode.value = lastNode.value.slice(0, match.index);
|
|
33
32
|
}
|
package/dist/dynamic-link.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
Link
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import
|
|
6
|
-
__objRest,
|
|
7
|
-
__spreadValues
|
|
8
|
-
} from "./chunk-CWMXXUWU.js";
|
|
4
|
+
} from "./chunk-DVOZJZGH.js";
|
|
5
|
+
import "./chunk-MLKGABMK.js";
|
|
9
6
|
|
|
10
7
|
// src/dynamic-link.tsx
|
|
11
8
|
import { useParams } from "next/navigation";
|
|
12
9
|
import { forwardRef, useMemo } from "react";
|
|
13
10
|
import { jsx } from "react/jsx-runtime";
|
|
14
11
|
var DynamicLink = forwardRef(
|
|
15
|
-
(
|
|
16
|
-
var _b = _a, { href } = _b, props = __objRest(_b, ["href"]);
|
|
12
|
+
({ href, ...props }, ref) => {
|
|
17
13
|
const params = useParams();
|
|
18
14
|
const url = useMemo(() => {
|
|
19
|
-
return href
|
|
15
|
+
return href?.replace(/\[.*\]/, (key) => {
|
|
20
16
|
const mappedKey = key.slice(1, -1);
|
|
21
17
|
const value = mappedKey in params ? params[mappedKey] : "undefined";
|
|
22
18
|
return typeof value === "string" ? value : value.join("/");
|
|
23
19
|
});
|
|
24
20
|
}, [params, href]);
|
|
25
|
-
return /* @__PURE__ */ jsx(Link,
|
|
21
|
+
return /* @__PURE__ */ jsx(Link, { ref, href: url, ...props });
|
|
26
22
|
}
|
|
27
23
|
);
|
|
28
24
|
DynamicLink.displayName = "DynamicLink";
|
package/dist/link.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
flattenNode,
|
|
3
3
|
remarkHeading
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-YKIM647L.js";
|
|
5
5
|
import {
|
|
6
6
|
slash
|
|
7
7
|
} from "../chunk-UWEEHUJV.js";
|
|
8
|
-
import
|
|
9
|
-
__spreadValues
|
|
10
|
-
} from "../chunk-CWMXXUWU.js";
|
|
8
|
+
import "../chunk-MLKGABMK.js";
|
|
11
9
|
|
|
12
10
|
// src/mdx-plugins/index.ts
|
|
13
11
|
import {
|
|
@@ -140,8 +138,14 @@ var defaultIcons = {
|
|
|
140
138
|
}
|
|
141
139
|
};
|
|
142
140
|
function transformerIcon(options = {}) {
|
|
143
|
-
const shortcuts =
|
|
144
|
-
|
|
141
|
+
const shortcuts = {
|
|
142
|
+
...defaultShortcuts,
|
|
143
|
+
...options.shortcuts
|
|
144
|
+
};
|
|
145
|
+
const icons = {
|
|
146
|
+
...defaultIcons,
|
|
147
|
+
...options.extend
|
|
148
|
+
};
|
|
145
149
|
const defaultIcon = "default" in icons ? icons.default : void 0;
|
|
146
150
|
return {
|
|
147
151
|
name: "rehype-code:icon",
|
|
@@ -162,15 +166,15 @@ function transformerIcon(options = {}) {
|
|
|
162
166
|
var metaValues = [
|
|
163
167
|
{
|
|
164
168
|
name: "title",
|
|
165
|
-
regex:
|
|
169
|
+
regex: /title="(?<value>[^"]*)"/
|
|
166
170
|
},
|
|
167
171
|
{
|
|
168
172
|
name: "custom",
|
|
169
|
-
regex:
|
|
173
|
+
regex: /custom="(?<value>[^"]+)"/
|
|
170
174
|
},
|
|
171
175
|
{
|
|
172
176
|
name: "tab",
|
|
173
|
-
regex:
|
|
177
|
+
regex: /tab="(?<value>[^"]+)"/
|
|
174
178
|
}
|
|
175
179
|
];
|
|
176
180
|
var rehypeCodeDefaultOptions = {
|
|
@@ -203,15 +207,17 @@ var rehypeCodeDefaultOptions = {
|
|
|
203
207
|
}
|
|
204
208
|
};
|
|
205
209
|
function rehypeCode(options = {}) {
|
|
206
|
-
const codeOptions =
|
|
207
|
-
|
|
210
|
+
const codeOptions = {
|
|
211
|
+
...rehypeCodeDefaultOptions,
|
|
212
|
+
...options
|
|
213
|
+
};
|
|
214
|
+
codeOptions.transformers ||= [];
|
|
208
215
|
codeOptions.transformers = [
|
|
209
216
|
{
|
|
210
217
|
name: "rehype-code:pre-process",
|
|
211
218
|
preprocess(code, { meta }) {
|
|
212
|
-
var _a;
|
|
213
219
|
if (meta && codeOptions.filterMetaString) {
|
|
214
|
-
meta.__raw = codeOptions.filterMetaString(
|
|
220
|
+
meta.__raw = codeOptions.filterMetaString(meta.__raw ?? "");
|
|
215
221
|
}
|
|
216
222
|
return code.replace(/\n$/, "");
|
|
217
223
|
},
|
|
@@ -245,7 +251,7 @@ function transformerTab() {
|
|
|
245
251
|
name: "rehype-code:tab",
|
|
246
252
|
root(root) {
|
|
247
253
|
const meta = this.options.meta;
|
|
248
|
-
if (typeof
|
|
254
|
+
if (typeof meta?.tab !== "string") return root;
|
|
249
255
|
return {
|
|
250
256
|
type: "root",
|
|
251
257
|
children: [
|
|
@@ -279,7 +285,6 @@ function remarkImage({
|
|
|
279
285
|
return (tree, _file, done) => {
|
|
280
286
|
const importsToInject = [];
|
|
281
287
|
visit(tree, "image", (node) => {
|
|
282
|
-
var _a;
|
|
283
288
|
let url = decodeURI(node.url);
|
|
284
289
|
if (!url || EXTERNAL_URL_REGEX.test(url)) {
|
|
285
290
|
return;
|
|
@@ -301,7 +306,7 @@ function remarkImage({
|
|
|
301
306
|
{
|
|
302
307
|
type: "mdxJsxAttribute",
|
|
303
308
|
name: "alt",
|
|
304
|
-
value:
|
|
309
|
+
value: node.alt ?? "image"
|
|
305
310
|
},
|
|
306
311
|
hasBlur && {
|
|
307
312
|
type: "mdxJsxAttribute",
|
|
@@ -372,14 +377,13 @@ function remarkStructure({
|
|
|
372
377
|
const data = { contents: [], headings: [] };
|
|
373
378
|
let lastHeading = "";
|
|
374
379
|
visit2(node, types, (element) => {
|
|
375
|
-
var _a, _b;
|
|
376
380
|
if (element.type === "root") return;
|
|
377
381
|
const content = flattenNode(element).trim();
|
|
378
382
|
if (element.type === "heading") {
|
|
379
|
-
element.data
|
|
380
|
-
|
|
383
|
+
element.data ||= {};
|
|
384
|
+
element.data.hProperties ||= {};
|
|
381
385
|
const properties = element.data.hProperties;
|
|
382
|
-
const id =
|
|
386
|
+
const id = properties.id ?? slugger.slug(content);
|
|
383
387
|
data.headings.push({
|
|
384
388
|
id,
|
|
385
389
|
content
|
package/dist/middleware.js
CHANGED
package/dist/search/client.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
__async
|
|
3
|
-
} from "../chunk-CWMXXUWU.js";
|
|
1
|
+
import "../chunk-MLKGABMK.js";
|
|
4
2
|
|
|
5
3
|
// src/search/client.ts
|
|
6
4
|
import { useEffect, useState } from "react";
|
|
7
5
|
import useSWR from "swr";
|
|
8
|
-
function fetchDocs(api, query, locale, tag) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return yield res.json();
|
|
18
|
-
});
|
|
6
|
+
async function fetchDocs(api, query, locale, tag) {
|
|
7
|
+
if (query.length === 0) return "empty";
|
|
8
|
+
const params = new URLSearchParams();
|
|
9
|
+
params.set("query", query);
|
|
10
|
+
if (locale) params.set("locale", locale);
|
|
11
|
+
if (tag) params.set("tag", tag);
|
|
12
|
+
const res = await fetch(`${api}?${params.toString()}`);
|
|
13
|
+
if (!res.ok) throw new Error(await res.text());
|
|
14
|
+
return await res.json();
|
|
19
15
|
}
|
|
20
16
|
function useDocsSearch(locale, tag, api = "/api/search", delayMs = 100) {
|
|
21
17
|
const [search, setSearch] = useState("");
|
package/dist/search/server.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
__async,
|
|
3
|
-
__spreadProps,
|
|
4
|
-
__spreadValues
|
|
5
|
-
} from "../chunk-CWMXXUWU.js";
|
|
1
|
+
import "../chunk-MLKGABMK.js";
|
|
6
2
|
|
|
7
3
|
// src/search/server.ts
|
|
8
4
|
import { Document } from "flexsearch";
|
|
@@ -10,18 +6,15 @@ import { NextResponse } from "next/server";
|
|
|
10
6
|
function create(search) {
|
|
11
7
|
return {
|
|
12
8
|
search,
|
|
13
|
-
GET(request) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
);
|
|
24
|
-
});
|
|
9
|
+
async GET(request) {
|
|
10
|
+
const query = request.nextUrl.searchParams.get("query");
|
|
11
|
+
if (!query) return NextResponse.json([]);
|
|
12
|
+
return NextResponse.json(
|
|
13
|
+
await search(query, {
|
|
14
|
+
tag: request.nextUrl.searchParams.get("tag") ?? void 0,
|
|
15
|
+
locale: request.nextUrl.searchParams.get("locale") ?? void 0
|
|
16
|
+
})
|
|
17
|
+
);
|
|
25
18
|
}
|
|
26
19
|
};
|
|
27
20
|
}
|
|
@@ -38,68 +31,67 @@ function createI18nSearchAPI(type, options) {
|
|
|
38
31
|
map.set(
|
|
39
32
|
v.language,
|
|
40
33
|
// @ts-expect-error -- Index depends on generic types
|
|
41
|
-
createSearchAPI(type,
|
|
34
|
+
createSearchAPI(type, {
|
|
35
|
+
...options,
|
|
42
36
|
language: v.language,
|
|
43
37
|
indexes: v.indexes
|
|
44
|
-
})
|
|
38
|
+
})
|
|
45
39
|
);
|
|
46
40
|
}
|
|
47
|
-
return create((query, searchOptions) =>
|
|
48
|
-
if (searchOptions
|
|
41
|
+
return create(async (query, searchOptions) => {
|
|
42
|
+
if (searchOptions?.locale) {
|
|
49
43
|
const handler = map.get(searchOptions.locale);
|
|
50
44
|
if (handler) return handler.search(query, searchOptions);
|
|
51
45
|
}
|
|
52
46
|
return [];
|
|
53
|
-
})
|
|
47
|
+
});
|
|
54
48
|
}
|
|
55
49
|
function initSearchAPI({ indexes, language }) {
|
|
56
50
|
const store = ["title", "url"];
|
|
57
|
-
function getDocument() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
depth: 1,
|
|
78
|
-
resolution: 9
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
field: "keywords",
|
|
83
|
-
tokenize: "strict",
|
|
51
|
+
async function getDocument() {
|
|
52
|
+
const items = typeof indexes === "function" ? await indexes() : indexes;
|
|
53
|
+
const index = new Document({
|
|
54
|
+
language,
|
|
55
|
+
optimize: true,
|
|
56
|
+
cache: 100,
|
|
57
|
+
document: {
|
|
58
|
+
id: "url",
|
|
59
|
+
store,
|
|
60
|
+
index: [
|
|
61
|
+
{
|
|
62
|
+
field: "title",
|
|
63
|
+
tokenize: "forward",
|
|
64
|
+
resolution: 9
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
field: "content",
|
|
68
|
+
tokenize: "strict",
|
|
69
|
+
context: {
|
|
70
|
+
depth: 1,
|
|
84
71
|
resolution: 9
|
|
85
72
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
content: page.content,
|
|
94
|
-
keywords: page.keywords
|
|
95
|
-
});
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
field: "keywords",
|
|
76
|
+
tokenize: "strict",
|
|
77
|
+
resolution: 9
|
|
78
|
+
}
|
|
79
|
+
]
|
|
96
80
|
}
|
|
97
|
-
return index;
|
|
98
81
|
});
|
|
82
|
+
for (const page of items) {
|
|
83
|
+
index.add({
|
|
84
|
+
title: page.title,
|
|
85
|
+
url: page.url,
|
|
86
|
+
content: page.content,
|
|
87
|
+
keywords: page.keywords
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return index;
|
|
99
91
|
}
|
|
100
92
|
const doc = getDocument();
|
|
101
|
-
return create((query) =>
|
|
102
|
-
const results = (
|
|
93
|
+
return create(async (query) => {
|
|
94
|
+
const results = (await doc).search(query, 5, {
|
|
103
95
|
enrich: true,
|
|
104
96
|
suggest: true
|
|
105
97
|
});
|
|
@@ -110,7 +102,7 @@ function initSearchAPI({ indexes, language }) {
|
|
|
110
102
|
id: page.doc.url,
|
|
111
103
|
url: page.doc.url
|
|
112
104
|
}));
|
|
113
|
-
})
|
|
105
|
+
});
|
|
114
106
|
}
|
|
115
107
|
function initSearchAPIAdvanced({
|
|
116
108
|
indexes,
|
|
@@ -118,85 +110,82 @@ function initSearchAPIAdvanced({
|
|
|
118
110
|
tag = false
|
|
119
111
|
}) {
|
|
120
112
|
const store = ["id", "url", "content", "page_id", "type", "keywords"];
|
|
121
|
-
function getDocument() {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
113
|
+
async function getDocument() {
|
|
114
|
+
const items = typeof indexes === "function" ? await indexes() : indexes;
|
|
115
|
+
const index = new Document({
|
|
116
|
+
language,
|
|
117
|
+
cache: 100,
|
|
118
|
+
optimize: true,
|
|
119
|
+
document: {
|
|
120
|
+
id: "id",
|
|
121
|
+
tag: tag ? "tag" : void 0,
|
|
122
|
+
store,
|
|
123
|
+
index: [
|
|
124
|
+
{
|
|
125
|
+
field: "content",
|
|
126
|
+
tokenize: "forward",
|
|
127
|
+
context: { depth: 2, bidirectional: true, resolution: 9 }
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
field: "keywords",
|
|
131
|
+
tokenize: "strict",
|
|
132
|
+
resolution: 9
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
for (const page of items) {
|
|
138
|
+
const data = page.structuredData;
|
|
139
|
+
let id = 0;
|
|
140
|
+
index.add({
|
|
141
|
+
id: page.id,
|
|
142
|
+
page_id: page.id,
|
|
143
|
+
type: "page",
|
|
144
|
+
content: page.title,
|
|
145
|
+
keywords: page.keywords,
|
|
146
|
+
tag: page.tag,
|
|
147
|
+
url: page.url
|
|
145
148
|
});
|
|
146
|
-
for (const
|
|
147
|
-
const data = page.structuredData;
|
|
148
|
-
let id = 0;
|
|
149
|
+
for (const heading of data.headings) {
|
|
149
150
|
index.add({
|
|
150
|
-
id: page.id,
|
|
151
|
+
id: page.id + (id++).toString(),
|
|
151
152
|
page_id: page.id,
|
|
152
|
-
type: "
|
|
153
|
-
content: page.title,
|
|
154
|
-
keywords: page.keywords,
|
|
153
|
+
type: "heading",
|
|
155
154
|
tag: page.tag,
|
|
156
|
-
url: page.url
|
|
155
|
+
url: `${page.url}#${heading.id}`,
|
|
156
|
+
content: heading.content
|
|
157
157
|
});
|
|
158
|
-
for (const heading of data.headings) {
|
|
159
|
-
index.add({
|
|
160
|
-
id: page.id + (id++).toString(),
|
|
161
|
-
page_id: page.id,
|
|
162
|
-
type: "heading",
|
|
163
|
-
tag: page.tag,
|
|
164
|
-
url: `${page.url}#${heading.id}`,
|
|
165
|
-
content: heading.content
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
for (const content of data.contents) {
|
|
169
|
-
index.add({
|
|
170
|
-
id: page.id + (id++).toString(),
|
|
171
|
-
page_id: page.id,
|
|
172
|
-
tag: page.tag,
|
|
173
|
-
type: "text",
|
|
174
|
-
url: content.heading ? `${page.url}#${content.heading}` : page.url,
|
|
175
|
-
content: content.content
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
158
|
}
|
|
179
|
-
|
|
180
|
-
|
|
159
|
+
for (const content of data.contents) {
|
|
160
|
+
index.add({
|
|
161
|
+
id: page.id + (id++).toString(),
|
|
162
|
+
page_id: page.id,
|
|
163
|
+
tag: page.tag,
|
|
164
|
+
type: "text",
|
|
165
|
+
url: content.heading ? `${page.url}#${content.heading}` : page.url,
|
|
166
|
+
content: content.content
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return index;
|
|
181
171
|
}
|
|
182
172
|
const doc = getDocument();
|
|
183
|
-
return create((query, options) =>
|
|
184
|
-
|
|
185
|
-
const index = yield doc;
|
|
173
|
+
return create(async (query, options) => {
|
|
174
|
+
const index = await doc;
|
|
186
175
|
const results = index.search(query, 5, {
|
|
187
176
|
enrich: true,
|
|
188
|
-
tag: options
|
|
177
|
+
tag: options?.tag,
|
|
189
178
|
limit: 6
|
|
190
179
|
});
|
|
191
180
|
const map = /* @__PURE__ */ new Map();
|
|
192
|
-
for (const item of
|
|
181
|
+
for (const item of results[0]?.result ?? []) {
|
|
193
182
|
if (item.doc.type === "page") {
|
|
194
183
|
if (!map.has(item.doc.id)) {
|
|
195
184
|
map.set(item.doc.id, []);
|
|
196
185
|
}
|
|
197
186
|
continue;
|
|
198
187
|
}
|
|
199
|
-
const list =
|
|
188
|
+
const list = map.get(item.doc.page_id) ?? [];
|
|
200
189
|
list.push({
|
|
201
190
|
id: item.doc.id,
|
|
202
191
|
content: item.doc.content,
|
|
@@ -218,7 +207,7 @@ function initSearchAPIAdvanced({
|
|
|
218
207
|
sortedResult.push(...items);
|
|
219
208
|
}
|
|
220
209
|
return sortedResult;
|
|
221
|
-
})
|
|
210
|
+
});
|
|
222
211
|
}
|
|
223
212
|
export {
|
|
224
213
|
createI18nSearchAPI,
|