@depup/fumadocs-core 16.6.17-depup.0
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/LICENSE +21 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/dist/advanced-BZKQwtss.js +72 -0
- package/dist/algolia-BcNfAtYC.d.ts +67 -0
- package/dist/breadcrumb.d.ts +47 -0
- package/dist/breadcrumb.js +61 -0
- package/dist/build-doc-BotvE-sS.js +81 -0
- package/dist/chunk-BoAXSpZd.js +33 -0
- package/dist/client-9fKBmECY.d.ts +218 -0
- package/dist/codeblock-utils-DBm7VMdU.d.ts +36 -0
- package/dist/config-CsHj5oV8.d.ts +16 -0
- package/dist/content/github.d.ts +50 -0
- package/dist/content/github.js +28 -0
- package/dist/content/md.d.ts +30 -0
- package/dist/content/md.js +45 -0
- package/dist/content/mdx/preset-bundler.d.ts +28 -0
- package/dist/content/mdx/preset-bundler.js +39 -0
- package/dist/content/mdx/preset-runtime.d.ts +26 -0
- package/dist/content/mdx/preset-runtime.js +36 -0
- package/dist/content/toc.d.ts +20 -0
- package/dist/content/toc.js +15 -0
- package/dist/definitions-AAtMxt2w.d.ts +61 -0
- package/dist/dynamic-link.d.ts +14 -0
- package/dist/dynamic-link.js +31 -0
- package/dist/endpoint-8Kwx_qOv.js +28 -0
- package/dist/framework/index.d.ts +49 -0
- package/dist/framework/index.js +65 -0
- package/dist/framework/next.d.ts +16 -0
- package/dist/framework/next.js +19 -0
- package/dist/framework/react-router.d.ts +16 -0
- package/dist/framework/react-router.js +43 -0
- package/dist/framework/tanstack.d.ts +19 -0
- package/dist/framework/tanstack.js +54 -0
- package/dist/framework/waku.d.ts +16 -0
- package/dist/framework/waku.js +48 -0
- package/dist/highlight/client.d.ts +12 -0
- package/dist/highlight/client.js +17 -0
- package/dist/highlight/config.d.ts +2 -0
- package/dist/highlight/config.js +27 -0
- package/dist/highlight/core/client.d.ts +31 -0
- package/dist/highlight/core/client.js +65 -0
- package/dist/highlight/core/index.d.ts +2 -0
- package/dist/highlight/core/index.js +62 -0
- package/dist/highlight/index.d.ts +34 -0
- package/dist/highlight/index.js +56 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +6 -0
- package/dist/i18n/middleware.d.ts +41 -0
- package/dist/i18n/middleware.js +55 -0
- package/dist/icon-DphlWQaF.js +17 -0
- package/dist/index-BDymJpj4.d.ts +45 -0
- package/dist/index-C5QIKZDy.d.ts +418 -0
- package/dist/index-Ch9QIdT6.d.ts +37 -0
- package/dist/index-Cq7hKKw4.d.ts +18 -0
- package/dist/index-CsYVANvj.d.ts +40 -0
- package/dist/index-DSpA1JO4.d.ts +27 -0
- package/dist/link.d.ts +19 -0
- package/dist/link.js +25 -0
- package/dist/mdast-utils-9tJwoVTq.js +39 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +2 -0
- package/dist/mdx-plugins/codeblock-utils.js +69 -0
- package/dist/mdx-plugins/index.d.ts +17 -0
- package/dist/mdx-plugins/index.js +18 -0
- package/dist/mdx-plugins/rehype-code.core.d.ts +2 -0
- package/dist/mdx-plugins/rehype-code.core.js +2 -0
- package/dist/mdx-plugins/rehype-code.d.ts +3 -0
- package/dist/mdx-plugins/rehype-code.js +23 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +2 -0
- package/dist/mdx-plugins/rehype-toc.js +118 -0
- package/dist/mdx-plugins/remark-admonition.d.ts +2 -0
- package/dist/mdx-plugins/remark-admonition.js +71 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +2 -0
- package/dist/mdx-plugins/remark-code-tab.js +181 -0
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +2 -0
- package/dist/mdx-plugins/remark-directive-admonition.js +57 -0
- package/dist/mdx-plugins/remark-feedback-block.d.ts +2 -0
- package/dist/mdx-plugins/remark-feedback-block.js +54 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +2 -0
- package/dist/mdx-plugins/remark-gfm.js +2 -0
- package/dist/mdx-plugins/remark-heading.d.ts +2 -0
- package/dist/mdx-plugins/remark-heading.js +46 -0
- package/dist/mdx-plugins/remark-image.d.ts +2 -0
- package/dist/mdx-plugins/remark-image.js +189 -0
- package/dist/mdx-plugins/remark-llms.d.ts +50 -0
- package/dist/mdx-plugins/remark-llms.js +30 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-files.js +184 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.js +28 -0
- package/dist/mdx-plugins/remark-npm.d.ts +2 -0
- package/dist/mdx-plugins/remark-npm.js +65 -0
- package/dist/mdx-plugins/remark-steps.d.ts +2 -0
- package/dist/mdx-plugins/remark-steps.js +74 -0
- package/dist/mdx-plugins/remark-structure.d.ts +2 -0
- package/dist/mdx-plugins/remark-structure.js +118 -0
- package/dist/mdx-plugins/stringifier.d.ts +2 -0
- package/dist/mdx-plugins/stringifier.js +86 -0
- package/dist/negotiation/index.d.ts +20 -0
- package/dist/negotiation/index.js +38 -0
- package/dist/normalize-url-J3kqKlu4.js +14 -0
- package/dist/page-tree/index.d.ts +3 -0
- package/dist/page-tree/index.js +2 -0
- package/dist/path-CYZclEPY.js +57 -0
- package/dist/rehype-code-B-bxz1EN.d.ts +17 -0
- package/dist/rehype-code.core-AzcK6-sL.js +245 -0
- package/dist/rehype-code.core-Ck9MowQQ.d.ts +52 -0
- package/dist/rehype-toc-BLsqqf_o.d.ts +45 -0
- package/dist/remark-admonition-DNKm8XsG.d.ts +21 -0
- package/dist/remark-code-tab-G7U6TydN.d.ts +31 -0
- package/dist/remark-directive-admonition-gkHghBYa.d.ts +35 -0
- package/dist/remark-feedback-block-90yTnyTC.d.ts +51 -0
- package/dist/remark-gfm-C2GLsTxH.d.ts +2 -0
- package/dist/remark-heading-DR_pmcPV.d.ts +45 -0
- package/dist/remark-image-CP5w6VTd.d.ts +64 -0
- package/dist/remark-mdx-files-C7gYD1Bn.d.ts +55 -0
- package/dist/remark-mdx-mermaid-CeZ2Fepw.d.ts +16 -0
- package/dist/remark-npm-BMre-WzD.d.ts +35 -0
- package/dist/remark-steps-9ooYFxUA.d.ts +27 -0
- package/dist/remark-structure-CILz6H_T.d.ts +94 -0
- package/dist/remove-markdown-C5S415Dz.js +38 -0
- package/dist/remove-undefined-Bfj4SlGF.js +17 -0
- package/dist/search/algolia.d.ts +2 -0
- package/dist/search/algolia.js +75 -0
- package/dist/search/client/algolia.d.ts +2 -0
- package/dist/search/client/algolia.js +57 -0
- package/dist/search/client/fetch.d.ts +2 -0
- package/dist/search/client/fetch.js +27 -0
- package/dist/search/client/flexsearch-static.d.ts +2 -0
- package/dist/search/client/flexsearch-static.js +41 -0
- package/dist/search/client/mixedbread.d.ts +2 -0
- package/dist/search/client/mixedbread.js +65 -0
- package/dist/search/client/orama-cloud-legacy.d.ts +2 -0
- package/dist/search/client/orama-cloud-legacy.js +84 -0
- package/dist/search/client/orama-cloud.d.ts +2 -0
- package/dist/search/client/orama-cloud.js +86 -0
- package/dist/search/client/orama-static.d.ts +2 -0
- package/dist/search/client/orama-static.js +53 -0
- package/dist/search/client.d.ts +2 -0
- package/dist/search/client.js +102 -0
- package/dist/search/flexsearch.d.ts +52 -0
- package/dist/search/flexsearch.js +104 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +68 -0
- package/dist/search/mixedbread.d.ts +50 -0
- package/dist/search/mixedbread.js +77 -0
- package/dist/search/orama-cloud-legacy.d.ts +75 -0
- package/dist/search/orama-cloud-legacy.js +48 -0
- package/dist/search/orama-cloud.d.ts +75 -0
- package/dist/search/orama-cloud.js +50 -0
- package/dist/search/server.d.ts +2 -0
- package/dist/search/server.js +232 -0
- package/dist/server-BVKBFI75.d.ts +138 -0
- package/dist/source/client/index.d.ts +2 -0
- package/dist/source/client/index.js +37 -0
- package/dist/source/index.d.ts +2 -0
- package/dist/source/index.js +786 -0
- package/dist/source/plugins/lucide-icons.d.ts +12 -0
- package/dist/source/plugins/lucide-icons.js +21 -0
- package/dist/source/plugins/slugs.d.ts +2 -0
- package/dist/source/plugins/slugs.js +62 -0
- package/dist/source/plugins/status-badges.d.ts +51 -0
- package/dist/source/plugins/status-badges.js +52 -0
- package/dist/source/schema.d.ts +27 -0
- package/dist/source/schema.js +26 -0
- package/dist/stringifier-CugaOXsb.d.ts +64 -0
- package/dist/toc-DmllTzmG.d.ts +55 -0
- package/dist/toc.d.ts +2 -0
- package/dist/toc.js +133 -0
- package/dist/types-3ccArm6T.d.ts +6 -0
- package/dist/util-CT8y1EgJ.js +8 -0
- package/dist/util-D_kBfbUQ.d.ts +7 -0
- package/dist/utils/use-media-query.d.ts +4 -0
- package/dist/utils/use-media-query.js +20 -0
- package/dist/utils/use-on-change.d.ts +9 -0
- package/dist/utils/use-on-change.js +20 -0
- package/dist/utils-6GexS7iX.js +134 -0
- package/dist/utils-ktUGajEb.js +59 -0
- package/package.json +272 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/search/algolia.ts
|
|
2
|
+
/**
|
|
3
|
+
* Update index settings and replace all objects
|
|
4
|
+
*
|
|
5
|
+
* @param client - Algolia Admin Client
|
|
6
|
+
* @param options - Index Options
|
|
7
|
+
*/
|
|
8
|
+
async function sync(client, options) {
|
|
9
|
+
const { indexName = "document", documents } = options;
|
|
10
|
+
await setIndexSettings(client, indexName);
|
|
11
|
+
await updateDocuments(client, indexName, documents);
|
|
12
|
+
}
|
|
13
|
+
async function setIndexSettings(client, indexName) {
|
|
14
|
+
await client.setSettings({
|
|
15
|
+
indexName,
|
|
16
|
+
indexSettings: {
|
|
17
|
+
attributeForDistinct: "page_id",
|
|
18
|
+
attributesToRetrieve: [
|
|
19
|
+
"title",
|
|
20
|
+
"section",
|
|
21
|
+
"content",
|
|
22
|
+
"url",
|
|
23
|
+
"section_id",
|
|
24
|
+
"breadcrumbs"
|
|
25
|
+
],
|
|
26
|
+
searchableAttributes: [
|
|
27
|
+
"title",
|
|
28
|
+
"section",
|
|
29
|
+
"content"
|
|
30
|
+
],
|
|
31
|
+
attributesToSnippet: [],
|
|
32
|
+
attributesForFaceting: ["tag"]
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function toIndex(page) {
|
|
37
|
+
let id = 0;
|
|
38
|
+
const indexes = [];
|
|
39
|
+
const scannedHeadings = /* @__PURE__ */ new Set();
|
|
40
|
+
function createIndex(section, sectionId, content) {
|
|
41
|
+
return {
|
|
42
|
+
objectID: `${page._id}-${(id++).toString()}`,
|
|
43
|
+
breadcrumbs: page.breadcrumbs,
|
|
44
|
+
title: page.title,
|
|
45
|
+
url: page.url,
|
|
46
|
+
page_id: page._id,
|
|
47
|
+
tag: page.tag,
|
|
48
|
+
section,
|
|
49
|
+
section_id: sectionId,
|
|
50
|
+
content,
|
|
51
|
+
...page.extra_data
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (page.description) indexes.push(createIndex(void 0, void 0, page.description));
|
|
55
|
+
const { headings, contents } = page.structured;
|
|
56
|
+
for (const p of contents) {
|
|
57
|
+
const heading = p.heading ? headings.find((h) => p.heading === h.id) : null;
|
|
58
|
+
const index = createIndex(heading?.content, heading?.id, p.content);
|
|
59
|
+
if (heading && !scannedHeadings.has(heading.id)) {
|
|
60
|
+
scannedHeadings.add(heading.id);
|
|
61
|
+
indexes.push(createIndex(heading.content, heading.id, heading.content));
|
|
62
|
+
}
|
|
63
|
+
indexes.push(index);
|
|
64
|
+
}
|
|
65
|
+
return indexes;
|
|
66
|
+
}
|
|
67
|
+
async function updateDocuments(client, indexName, documents) {
|
|
68
|
+
const objects = documents.flatMap(toIndex);
|
|
69
|
+
await client.replaceAllObjects({
|
|
70
|
+
indexName,
|
|
71
|
+
objects
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { setIndexSettings, sync, updateDocuments };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createContentHighlighter } from "../index.js";
|
|
2
|
+
//#region src/search/client/algolia.ts
|
|
3
|
+
function groupResults(hits) {
|
|
4
|
+
const grouped = [];
|
|
5
|
+
const scannedUrls = /* @__PURE__ */ new Set();
|
|
6
|
+
for (const hit of hits) {
|
|
7
|
+
if (!scannedUrls.has(hit.url)) {
|
|
8
|
+
scannedUrls.add(hit.url);
|
|
9
|
+
grouped.push({
|
|
10
|
+
id: hit.url,
|
|
11
|
+
type: "page",
|
|
12
|
+
breadcrumbs: hit.breadcrumbs,
|
|
13
|
+
url: hit.url,
|
|
14
|
+
content: hit.title
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
grouped.push({
|
|
18
|
+
id: hit.objectID,
|
|
19
|
+
type: hit.content === hit.section ? "heading" : "text",
|
|
20
|
+
url: hit.section_id ? `${hit.url}#${hit.section_id}` : hit.url,
|
|
21
|
+
content: hit.content
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return grouped;
|
|
25
|
+
}
|
|
26
|
+
function algoliaClient(options) {
|
|
27
|
+
const { indexName, onSearch, client, locale, tag } = options;
|
|
28
|
+
return {
|
|
29
|
+
deps: [
|
|
30
|
+
indexName,
|
|
31
|
+
client,
|
|
32
|
+
locale,
|
|
33
|
+
tag
|
|
34
|
+
],
|
|
35
|
+
async search(query) {
|
|
36
|
+
if (query.trim().length === 0) return [];
|
|
37
|
+
const result = onSearch ? await onSearch(query, tag, locale) : await client.searchForHits({ requests: [{
|
|
38
|
+
type: "default",
|
|
39
|
+
indexName,
|
|
40
|
+
query,
|
|
41
|
+
distinct: 5,
|
|
42
|
+
hitsPerPage: 10,
|
|
43
|
+
filters: tag ? `tag:${tag}` : void 0
|
|
44
|
+
}] });
|
|
45
|
+
const highlighter = createContentHighlighter(query);
|
|
46
|
+
return groupResults(result.results[0].hits).flatMap((hit) => {
|
|
47
|
+
if (hit.type === "page") return {
|
|
48
|
+
...hit,
|
|
49
|
+
content: highlighter.highlightMarkdown(hit.content)
|
|
50
|
+
};
|
|
51
|
+
return [];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { algoliaClient };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/search/client/fetch.ts
|
|
2
|
+
const globalCache = /* @__PURE__ */ new Map();
|
|
3
|
+
function fetchClient({ api = "/api/search", locale, tag, cache = globalCache } = {}) {
|
|
4
|
+
return {
|
|
5
|
+
deps: [
|
|
6
|
+
api,
|
|
7
|
+
locale,
|
|
8
|
+
tag
|
|
9
|
+
],
|
|
10
|
+
async search(query) {
|
|
11
|
+
const url = new URL(api, window.location.origin);
|
|
12
|
+
url.searchParams.set("query", query);
|
|
13
|
+
if (locale) url.searchParams.set("locale", locale);
|
|
14
|
+
if (tag) url.searchParams.set("tag", Array.isArray(tag) ? tag.join(",") : tag);
|
|
15
|
+
const key = url.toString();
|
|
16
|
+
const cached = cache.get(key);
|
|
17
|
+
if (cached) return cached;
|
|
18
|
+
const res = await fetch(url);
|
|
19
|
+
if (!res.ok) throw new Error(await res.text());
|
|
20
|
+
const result = await res.json();
|
|
21
|
+
cache.set(key, result);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { fetchClient };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { n as search, t as createDocument } from "../../utils-ktUGajEb.js";
|
|
2
|
+
//#region src/search/client/flexsearch-static.ts
|
|
3
|
+
function initDocument(data) {
|
|
4
|
+
const document = createDocument();
|
|
5
|
+
for (const [k, v] of Object.entries(data)) document.import(k, v);
|
|
6
|
+
return document;
|
|
7
|
+
}
|
|
8
|
+
const cacheMap = /* @__PURE__ */ new Map();
|
|
9
|
+
function flexsearchStaticClient(options = {}) {
|
|
10
|
+
const { from = "/api/search", locale = "", tag } = options;
|
|
11
|
+
let dbs = cacheMap.get(from);
|
|
12
|
+
if (!dbs) {
|
|
13
|
+
dbs = init(from);
|
|
14
|
+
cacheMap.set(from, dbs);
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
deps: [
|
|
18
|
+
from,
|
|
19
|
+
locale,
|
|
20
|
+
tag
|
|
21
|
+
],
|
|
22
|
+
async search(query) {
|
|
23
|
+
const db = (await dbs).get(locale);
|
|
24
|
+
if (!db) return [];
|
|
25
|
+
return search(db, query, tag);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function init(from) {
|
|
30
|
+
const res = await fetch(from);
|
|
31
|
+
if (!res.ok) throw new Error(`failed to fetch exported search indexes from ${from}, make sure the search database is exported and available for client.`);
|
|
32
|
+
const data = await res.json();
|
|
33
|
+
const dbs = /* @__PURE__ */ new Map();
|
|
34
|
+
if (data.type === "i18n") {
|
|
35
|
+
for (const [locale, map] of Object.entries(data.raw)) dbs.set(locale, initDocument(map));
|
|
36
|
+
return dbs;
|
|
37
|
+
} else dbs.set("", initDocument(data.raw));
|
|
38
|
+
return dbs;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { flexsearchStaticClient };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { r as __toESM } from "../../chunk-BoAXSpZd.js";
|
|
2
|
+
import { t as require_remove_markdown } from "../../remove-markdown-C5S415Dz.js";
|
|
3
|
+
import Slugger from "github-slugger";
|
|
4
|
+
//#region src/search/client/mixedbread.ts
|
|
5
|
+
var import_remove_markdown = /* @__PURE__ */ __toESM(require_remove_markdown(), 1);
|
|
6
|
+
const slugger = new Slugger();
|
|
7
|
+
function extractHeadingTitle(text) {
|
|
8
|
+
const trimmedText = text.trim();
|
|
9
|
+
if (!trimmedText.startsWith("#")) return "";
|
|
10
|
+
const firstLine = trimmedText.split("\n")[0]?.trim();
|
|
11
|
+
if (firstLine) return (0, import_remove_markdown.default)(firstLine, { useImgAltText: false });
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `createMixedbreadSearchAPI` from `fumadocs-core/search/mixedbread` instead.
|
|
16
|
+
* This client-side approach exposes your API key in the browser.
|
|
17
|
+
* The server-side approach keeps the key secure and uses `type: 'fetch'` on the client.
|
|
18
|
+
*/
|
|
19
|
+
function mixedbreadClient(options) {
|
|
20
|
+
const { client, storeIdentifier, tag } = options;
|
|
21
|
+
return {
|
|
22
|
+
deps: [
|
|
23
|
+
client,
|
|
24
|
+
storeIdentifier,
|
|
25
|
+
tag
|
|
26
|
+
],
|
|
27
|
+
async search(query) {
|
|
28
|
+
if (!query.trim()) return [];
|
|
29
|
+
return (await client.stores.search({
|
|
30
|
+
query,
|
|
31
|
+
store_identifiers: [storeIdentifier],
|
|
32
|
+
top_k: 10,
|
|
33
|
+
filters: {
|
|
34
|
+
key: "generated_metadata.tag",
|
|
35
|
+
operator: "eq",
|
|
36
|
+
value: tag
|
|
37
|
+
},
|
|
38
|
+
search_options: { return_metadata: true }
|
|
39
|
+
})).data.flatMap((item) => {
|
|
40
|
+
const metadata = item.generated_metadata;
|
|
41
|
+
const url = metadata.url || "#";
|
|
42
|
+
const title = metadata.title || "Untitled";
|
|
43
|
+
const chunkResults = [{
|
|
44
|
+
id: `${item.file_id}-${item.chunk_index}-page`,
|
|
45
|
+
type: "page",
|
|
46
|
+
content: title,
|
|
47
|
+
url
|
|
48
|
+
}];
|
|
49
|
+
const headingTitle = item.type === "text" && item.text ? extractHeadingTitle(item.text) : "";
|
|
50
|
+
if (headingTitle) {
|
|
51
|
+
slugger.reset();
|
|
52
|
+
chunkResults.push({
|
|
53
|
+
id: `${item.file_id}-${item.chunk_index}-heading`,
|
|
54
|
+
type: "heading",
|
|
55
|
+
content: headingTitle,
|
|
56
|
+
url: `${url}#${slugger.slug(headingTitle)}`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return chunkResults;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { mixedbreadClient };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createContentHighlighter } from "../index.js";
|
|
2
|
+
import { t as removeUndefined } from "../../remove-undefined-Bfj4SlGF.js";
|
|
3
|
+
//#region src/search/client/orama-cloud-legacy.ts
|
|
4
|
+
function oramaCloudLegacyClient(options) {
|
|
5
|
+
const { index = "default", client, params: extraParams = {}, tag } = options;
|
|
6
|
+
return {
|
|
7
|
+
deps: [
|
|
8
|
+
index,
|
|
9
|
+
client,
|
|
10
|
+
tag
|
|
11
|
+
],
|
|
12
|
+
async search(query) {
|
|
13
|
+
const highlighter = createContentHighlighter(query);
|
|
14
|
+
const list = [];
|
|
15
|
+
if (index === "crawler") {
|
|
16
|
+
const result = await client.search({
|
|
17
|
+
...extraParams,
|
|
18
|
+
term: query,
|
|
19
|
+
where: {
|
|
20
|
+
category: tag ? { eq: tag.slice(0, 1).toUpperCase() + tag.slice(1) } : void 0,
|
|
21
|
+
...extraParams.where
|
|
22
|
+
},
|
|
23
|
+
limit: 10
|
|
24
|
+
});
|
|
25
|
+
if (!result) return list;
|
|
26
|
+
for (const hit of result.hits) {
|
|
27
|
+
const doc = hit.document;
|
|
28
|
+
list.push({
|
|
29
|
+
id: hit.id,
|
|
30
|
+
type: "page",
|
|
31
|
+
content: highlighter.highlightMarkdown(doc.title),
|
|
32
|
+
url: doc.path
|
|
33
|
+
}, {
|
|
34
|
+
id: "page" + hit.id,
|
|
35
|
+
type: "text",
|
|
36
|
+
content: highlighter.highlightMarkdown(doc.content),
|
|
37
|
+
url: doc.path
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return list;
|
|
41
|
+
}
|
|
42
|
+
const params = {
|
|
43
|
+
...extraParams,
|
|
44
|
+
term: query,
|
|
45
|
+
where: removeUndefined({
|
|
46
|
+
tag,
|
|
47
|
+
...extraParams.where
|
|
48
|
+
}),
|
|
49
|
+
groupBy: {
|
|
50
|
+
properties: ["page_id"],
|
|
51
|
+
maxResult: 7,
|
|
52
|
+
...extraParams.groupBy
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const result = await client.search(params);
|
|
56
|
+
if (!result || !result.groups) return list;
|
|
57
|
+
for (const item of result.groups) {
|
|
58
|
+
let addedHead = false;
|
|
59
|
+
for (const hit of item.result) {
|
|
60
|
+
const doc = hit.document;
|
|
61
|
+
if (!addedHead) {
|
|
62
|
+
list.push({
|
|
63
|
+
id: doc.page_id,
|
|
64
|
+
type: "page",
|
|
65
|
+
content: highlighter.highlightMarkdown(doc.title),
|
|
66
|
+
breadcrumbs: doc.breadcrumbs,
|
|
67
|
+
url: doc.url
|
|
68
|
+
});
|
|
69
|
+
addedHead = true;
|
|
70
|
+
}
|
|
71
|
+
list.push({
|
|
72
|
+
id: doc.id,
|
|
73
|
+
content: highlighter.highlightMarkdown(doc.content),
|
|
74
|
+
type: doc.content === doc.section ? "heading" : "text",
|
|
75
|
+
url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return list;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { oramaCloudLegacyClient };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createContentHighlighter } from "../index.js";
|
|
2
|
+
import { t as removeUndefined } from "../../remove-undefined-Bfj4SlGF.js";
|
|
3
|
+
//#region src/search/client/orama-cloud.ts
|
|
4
|
+
function oramaCloudClient(options) {
|
|
5
|
+
const { index = "default", client, params: extraParams, tag } = options;
|
|
6
|
+
return {
|
|
7
|
+
deps: [
|
|
8
|
+
index,
|
|
9
|
+
client,
|
|
10
|
+
tag
|
|
11
|
+
],
|
|
12
|
+
async search(query) {
|
|
13
|
+
const highlighter = createContentHighlighter(query);
|
|
14
|
+
const list = [];
|
|
15
|
+
if (index === "crawler") {
|
|
16
|
+
const result = await client.search({
|
|
17
|
+
datasources: [],
|
|
18
|
+
...extraParams,
|
|
19
|
+
term: query,
|
|
20
|
+
where: {
|
|
21
|
+
category: tag ? { eq: tag.slice(0, 1).toUpperCase() + tag.slice(1) } : void 0,
|
|
22
|
+
...extraParams?.where
|
|
23
|
+
},
|
|
24
|
+
limit: 10
|
|
25
|
+
});
|
|
26
|
+
if (!result) return list;
|
|
27
|
+
for (const hit of result.hits) {
|
|
28
|
+
const doc = hit.document;
|
|
29
|
+
list.push({
|
|
30
|
+
id: hit.id,
|
|
31
|
+
type: "page",
|
|
32
|
+
content: highlighter.highlightMarkdown(doc.title),
|
|
33
|
+
url: doc.path
|
|
34
|
+
}, {
|
|
35
|
+
id: "page" + hit.id,
|
|
36
|
+
type: "text",
|
|
37
|
+
content: highlighter.highlightMarkdown(doc.content),
|
|
38
|
+
url: doc.path
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return list;
|
|
42
|
+
}
|
|
43
|
+
const result = await client.search({
|
|
44
|
+
datasources: [],
|
|
45
|
+
...extraParams,
|
|
46
|
+
term: query,
|
|
47
|
+
limit: 20,
|
|
48
|
+
where: removeUndefined({
|
|
49
|
+
tag,
|
|
50
|
+
...extraParams?.where
|
|
51
|
+
}),
|
|
52
|
+
groupBy: {
|
|
53
|
+
properties: ["page_id"],
|
|
54
|
+
max_results: 7,
|
|
55
|
+
...extraParams?.groupBy
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (!result || !result.groups) return list;
|
|
59
|
+
for (const item of result.groups) {
|
|
60
|
+
let addedHead = false;
|
|
61
|
+
for (const hit of item.result) {
|
|
62
|
+
const doc = hit.document;
|
|
63
|
+
if (!addedHead) {
|
|
64
|
+
list.push({
|
|
65
|
+
id: doc.page_id,
|
|
66
|
+
type: "page",
|
|
67
|
+
content: highlighter.highlightMarkdown(doc.title),
|
|
68
|
+
breadcrumbs: doc.breadcrumbs,
|
|
69
|
+
url: doc.url
|
|
70
|
+
});
|
|
71
|
+
addedHead = true;
|
|
72
|
+
}
|
|
73
|
+
list.push({
|
|
74
|
+
id: doc.id,
|
|
75
|
+
content: highlighter.highlightMarkdown(doc.content),
|
|
76
|
+
type: doc.content === doc.section ? "heading" : "text",
|
|
77
|
+
url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return list.length > 80 ? list.slice(0, 80) : list;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { oramaCloudClient };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { n as searchSimple, t as searchAdvanced } from "../../advanced-BZKQwtss.js";
|
|
2
|
+
import { create, load } from "@orama/orama";
|
|
3
|
+
//#region src/search/client/orama-static.ts
|
|
4
|
+
const cache = /* @__PURE__ */ new Map();
|
|
5
|
+
async function loadDB({ from = "/api/search", initOrama = (locale) => create({
|
|
6
|
+
schema: { _: "string" },
|
|
7
|
+
language: locale
|
|
8
|
+
}) } = {}) {
|
|
9
|
+
const cacheKey = from;
|
|
10
|
+
const cached = cache.get(cacheKey);
|
|
11
|
+
if (cached) return cached;
|
|
12
|
+
async function init() {
|
|
13
|
+
const res = await fetch(from);
|
|
14
|
+
if (!res.ok) throw new Error(`failed to fetch exported search indexes from ${from}, make sure the search database is exported and available for client.`);
|
|
15
|
+
const data = await res.json();
|
|
16
|
+
const dbs = /* @__PURE__ */ new Map();
|
|
17
|
+
if (data.type === "i18n") {
|
|
18
|
+
await Promise.all(Object.entries(data.data).map(async ([k, v]) => {
|
|
19
|
+
const db = await initOrama(k);
|
|
20
|
+
load(db, v);
|
|
21
|
+
dbs.set(k, {
|
|
22
|
+
type: v.type,
|
|
23
|
+
db
|
|
24
|
+
});
|
|
25
|
+
}));
|
|
26
|
+
return dbs;
|
|
27
|
+
}
|
|
28
|
+
const db = await initOrama();
|
|
29
|
+
load(db, data);
|
|
30
|
+
dbs.set("", {
|
|
31
|
+
type: data.type,
|
|
32
|
+
db
|
|
33
|
+
});
|
|
34
|
+
return dbs;
|
|
35
|
+
}
|
|
36
|
+
const result = init();
|
|
37
|
+
cache.set(cacheKey, result);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
function oramaStaticClient(options) {
|
|
41
|
+
const { tag, locale } = options;
|
|
42
|
+
return {
|
|
43
|
+
deps: [tag, locale],
|
|
44
|
+
async search(query) {
|
|
45
|
+
const db = (await loadDB(options)).get(locale ?? "");
|
|
46
|
+
if (!db) return [];
|
|
47
|
+
if (db.type === "simple") return searchSimple(db, query);
|
|
48
|
+
return searchAdvanced(db.db, query, tag);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { oramaStaticClient };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as FetchOptions, d as OramaCloudOptions, h as StaticOptions, n as SearchClient, p as AlgoliaOptions, r as useDocsSearch, t as ClientPreset } from "../client-9fKBmECY.js";
|
|
2
|
+
export { AlgoliaOptions, ClientPreset, FetchOptions, OramaCloudOptions, SearchClient, StaticOptions, useDocsSearch };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useOnChange } from "../utils/use-on-change.js";
|
|
2
|
+
import { use, useEffect, useRef, useState } from "react";
|
|
3
|
+
//#region src/utils/use-debounce.ts
|
|
4
|
+
function useDebounce(value, delayMs = 1e3) {
|
|
5
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (delayMs === 0) return;
|
|
8
|
+
const handler = window.setTimeout(() => {
|
|
9
|
+
setDebouncedValue(value);
|
|
10
|
+
}, delayMs);
|
|
11
|
+
return () => clearTimeout(handler);
|
|
12
|
+
}, [delayMs, value]);
|
|
13
|
+
if (delayMs === 0) return value;
|
|
14
|
+
return debouncedValue;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/search/client.ts
|
|
18
|
+
const promiseMap = {};
|
|
19
|
+
/**
|
|
20
|
+
* Provide a hook to query different official search clients.
|
|
21
|
+
*
|
|
22
|
+
* Note: it will re-query when its parameters changed, make sure to define `deps` array if you encounter rendering issues.
|
|
23
|
+
*/
|
|
24
|
+
function useDocsSearch(clientOptions, deps) {
|
|
25
|
+
const { delayMs = 100, allowEmpty = false, ...clientRest } = clientOptions;
|
|
26
|
+
const [search, setSearch] = useState("");
|
|
27
|
+
const [results, setResults] = useState("empty");
|
|
28
|
+
const [error, setError] = useState();
|
|
29
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
30
|
+
const debouncedValue = useDebounce(search, delayMs);
|
|
31
|
+
const onStart = useRef(void 0);
|
|
32
|
+
let client;
|
|
33
|
+
if ("type" in clientRest) switch (clientRest.type) {
|
|
34
|
+
case "fetch": {
|
|
35
|
+
const { fetchClient } = use(promiseMap[clientRest.type] ??= import("./client/fetch.js"));
|
|
36
|
+
client = fetchClient(clientRest);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "algolia": {
|
|
40
|
+
const { algoliaClient } = use(promiseMap[clientRest.type] ??= import("./client/algolia.js"));
|
|
41
|
+
client = algoliaClient(clientRest);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "orama-cloud": {
|
|
45
|
+
const { oramaCloudClient } = use(promiseMap[clientRest.type] ??= import("./client/orama-cloud.js"));
|
|
46
|
+
client = oramaCloudClient(clientRest);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "orama-cloud-legacy": {
|
|
50
|
+
const { oramaCloudLegacyClient } = use(promiseMap[clientRest.type] ??= import("./client/orama-cloud-legacy.js"));
|
|
51
|
+
client = oramaCloudLegacyClient(clientRest);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "mixedbread": {
|
|
55
|
+
const { mixedbreadClient } = use(promiseMap[clientRest.type] ??= import("./client/mixedbread.js"));
|
|
56
|
+
client = mixedbreadClient(clientRest);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "static": {
|
|
60
|
+
const { oramaStaticClient } = use(promiseMap[clientRest.type] ??= import("./client/orama-static.js"));
|
|
61
|
+
client = oramaStaticClient(clientRest);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
default: throw new Error("unknown search client");
|
|
65
|
+
}
|
|
66
|
+
else client = clientRest.client;
|
|
67
|
+
useOnChange([deps ?? client.deps, debouncedValue], () => {
|
|
68
|
+
if (onStart.current) {
|
|
69
|
+
onStart.current();
|
|
70
|
+
onStart.current = void 0;
|
|
71
|
+
}
|
|
72
|
+
setIsLoading(true);
|
|
73
|
+
let interrupt = false;
|
|
74
|
+
onStart.current = () => {
|
|
75
|
+
interrupt = true;
|
|
76
|
+
};
|
|
77
|
+
async function run() {
|
|
78
|
+
if (debouncedValue.length === 0 && !allowEmpty) return "empty";
|
|
79
|
+
return client.search(debouncedValue);
|
|
80
|
+
}
|
|
81
|
+
run().then((res) => {
|
|
82
|
+
if (interrupt) return;
|
|
83
|
+
setError(void 0);
|
|
84
|
+
setResults(res);
|
|
85
|
+
}).catch((err) => {
|
|
86
|
+
setError(err);
|
|
87
|
+
}).finally(() => {
|
|
88
|
+
setIsLoading(false);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
search,
|
|
93
|
+
setSearch,
|
|
94
|
+
query: {
|
|
95
|
+
isLoading,
|
|
96
|
+
data: results,
|
|
97
|
+
error
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { useDocsSearch };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { t as Awaitable } from "../types-3ccArm6T.js";
|
|
2
|
+
import { t as I18nConfig } from "../index-CsYVANvj.js";
|
|
3
|
+
import { m as SharedIndex, n as SearchAPI, t as QueryOptions } from "../server-BVKBFI75.js";
|
|
4
|
+
import { i as LoaderConfig, o as LoaderOutput, u as Page } from "../index-C5QIKZDy.js";
|
|
5
|
+
import { DocumentData, DocumentOptions } from "flexsearch";
|
|
6
|
+
|
|
7
|
+
//#region src/search/server/build-doc.d.ts
|
|
8
|
+
interface SharedDocument {
|
|
9
|
+
id: string;
|
|
10
|
+
content: string;
|
|
11
|
+
page_id: string;
|
|
12
|
+
type: 'page' | 'heading' | 'text';
|
|
13
|
+
breadcrumbs?: string[];
|
|
14
|
+
tags: string[];
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/search/flexsearch/utils.d.ts
|
|
19
|
+
type Doc = SharedDocument & DocumentData;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/search/flexsearch.d.ts
|
|
22
|
+
type Index = SharedIndex;
|
|
23
|
+
interface IndexWithLocale extends Index {
|
|
24
|
+
locale: string;
|
|
25
|
+
}
|
|
26
|
+
interface Options {
|
|
27
|
+
indexes: Index[] | (() => Awaitable<Index[]>);
|
|
28
|
+
document?: DocumentOptions<Doc>;
|
|
29
|
+
}
|
|
30
|
+
type ExportedData = {
|
|
31
|
+
type: 'default';
|
|
32
|
+
raw: Record<string, string>;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'i18n';
|
|
35
|
+
raw: Record<string, Record<string, string>>;
|
|
36
|
+
};
|
|
37
|
+
interface I18nOptions extends Omit<Options, 'indexes'> {
|
|
38
|
+
i18n: I18nConfig;
|
|
39
|
+
indexes: IndexWithLocale[] | (() => Awaitable<IndexWithLocale[]>);
|
|
40
|
+
/**
|
|
41
|
+
* options for each locale, see https://github.com/nextapps-de/flexsearch/blob/master/doc/encoder.md.
|
|
42
|
+
*/
|
|
43
|
+
localeMap?: Record<string, Partial<DocumentOptions<Doc>> | 'cjk'>;
|
|
44
|
+
}
|
|
45
|
+
declare function flexsearch(options: Options): SearchAPI;
|
|
46
|
+
declare function flexsearchI18n(options: I18nOptions): SearchAPI;
|
|
47
|
+
interface FromSourceOptions<C extends LoaderConfig> extends Pick<I18nOptions, 'localeMap' | 'document'> {
|
|
48
|
+
buildIndex?: (page: Page<C['source']['pageData']>) => Awaitable<Index>;
|
|
49
|
+
}
|
|
50
|
+
declare function flexsearchFromSource<C extends LoaderConfig>(loader: LoaderOutput<C>, options?: FromSourceOptions<NoInfer<C>>): SearchAPI<QueryOptions>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { ExportedData, FromSourceOptions, I18nOptions, Index, IndexWithLocale, Options, flexsearch, flexsearchFromSource, flexsearchI18n };
|