@vezham/docs-core 1.0.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/advanced-Ct13khZr.js +79 -0
- package/dist/algolia-C0E5qQhM.d.ts +66 -0
- package/dist/breadcrumb.d.ts +46 -0
- package/dist/breadcrumb.js +59 -0
- package/dist/build-doc-4OvfjVN2.js +85 -0
- package/dist/client-kQ39Ub0-.d.ts +247 -0
- package/dist/codeblock-utils-CyP8qsYv.d.ts +29 -0
- package/dist/content/github.d.ts +41 -0
- package/dist/content/github.js +28 -0
- package/dist/content/md/frontmatter.d.ts +15 -0
- package/dist/content/md/frontmatter.js +24 -0
- package/dist/content/md.d.ts +24 -0
- package/dist/content/md.js +43 -0
- package/dist/content/mdx/preset-bundler.d.ts +29 -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 +19 -0
- package/dist/content/toc.js +14 -0
- package/dist/definitions-CFOhwE1k.d.ts +72 -0
- package/dist/dynamic-CTsodhTH.js +905 -0
- package/dist/dynamic-link.d.ts +12 -0
- package/dist/dynamic-link.js +31 -0
- package/dist/endpoint-MyoBU5IC.js +28 -0
- package/dist/framework/astro.d.ts +21 -0
- package/dist/framework/astro.js +52 -0
- package/dist/framework/index.d.ts +40 -0
- package/dist/framework/index.js +66 -0
- package/dist/framework/next.d.ts +10 -0
- package/dist/framework/next.js +19 -0
- package/dist/framework/react-router.d.ts +10 -0
- package/dist/framework/react-router.js +43 -0
- package/dist/framework/tanstack.d.ts +13 -0
- package/dist/framework/tanstack.js +54 -0
- package/dist/framework/waku.d.ts +10 -0
- package/dist/framework/waku.js +46 -0
- package/dist/highlight/client.d.ts +11 -0
- package/dist/highlight/client.js +15 -0
- package/dist/highlight/index.d.ts +31 -0
- package/dist/highlight/index.js +30 -0
- package/dist/highlight/shiki/full.d.ts +7 -0
- package/dist/highlight/shiki/full.js +23 -0
- package/dist/highlight/shiki/index.d.ts +2 -0
- package/dist/highlight/shiki/index.js +27 -0
- package/dist/highlight/shiki/react.d.ts +23 -0
- package/dist/highlight/shiki/react.js +50 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +63 -0
- package/dist/i18n/middleware.d.ts +34 -0
- package/dist/i18n/middleware.js +3855 -0
- package/dist/icon-BILaoXeg.js +17 -0
- package/dist/index-B-0R0VbS.d.ts +18 -0
- package/dist/index-BM36H-xw.d.ts +36 -0
- package/dist/index-BMEUQz-F.d.ts +21 -0
- package/dist/index-DAYtLGbx.d.ts +16 -0
- package/dist/index-DIwKCYOz.d.ts +513 -0
- package/dist/index-DydiXvgS.d.ts +90 -0
- package/dist/index-E8Qh_yQs.d.ts +49 -0
- package/dist/is-equal-LdLqRs0o.js +8 -0
- package/dist/link.d.ts +17 -0
- package/dist/link.js +23 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +2 -0
- package/dist/mdx-plugins/codeblock-utils.js +68 -0
- package/dist/mdx-plugins/index.d.ts +20 -0
- package/dist/mdx-plugins/index.js +18 -0
- package/dist/mdx-plugins/rehype-code.core.d.ts +3 -0
- package/dist/mdx-plugins/rehype-code.core.js +3 -0
- package/dist/mdx-plugins/rehype-code.d.ts +4 -0
- package/dist/mdx-plugins/rehype-code.js +24 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +2 -0
- package/dist/mdx-plugins/rehype-toc.js +139 -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-block-id.d.ts +37 -0
- package/dist/mdx-plugins/remark-block-id.js +41 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +2 -0
- package/dist/mdx-plugins/remark-code-tab.js +190 -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 +167 -0
- package/dist/mdx-plugins/remark-llms.d.ts +2 -0
- package/dist/mdx-plugins/remark-llms.js +338 -0
- package/dist/mdx-plugins/remark-llms.runtime.d.ts +10 -0
- package/dist/mdx-plugins/remark-llms.runtime.js +24 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-files.js +182 -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 +76 -0
- package/dist/mdx-plugins/remark-steps.d.ts +2 -0
- package/dist/mdx-plugins/remark-steps.js +93 -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 +91 -0
- package/dist/mdx-plugins/transformer-icon.d.ts +2 -0
- package/dist/mdx-plugins/transformer-icon.js +145 -0
- package/dist/negotiation/index.d.ts +17 -0
- package/dist/negotiation/index.js +378 -0
- package/dist/page-tree/index.d.ts +3 -0
- package/dist/page-tree/index.js +2 -0
- package/dist/path-1H5VzYiT.js +75 -0
- package/dist/rehype-code-D-RFJb9W.d.ts +14 -0
- package/dist/rehype-code.core-BUwNuchP.js +548 -0
- package/dist/rehype-code.core-BjH1uHWj.d.ts +115 -0
- package/dist/rehype-toc-K51AGb5U.d.ts +43 -0
- package/dist/remark-admonition-BwTcmI_S.d.ts +20 -0
- package/dist/remark-code-tab-DE_4bdnu.d.ts +34 -0
- package/dist/remark-directive-admonition-BLiJ5l43.d.ts +27 -0
- package/dist/remark-feedback-block-BxtINXN-.d.ts +45 -0
- package/dist/remark-gfm-DpVfAX1x.d.ts +2 -0
- package/dist/remark-heading-DEIzTkU5.d.ts +33 -0
- package/dist/remark-image-BI2S9LOb.d.ts +57 -0
- package/dist/remark-llms-bD3WvU2V.d.ts +73 -0
- package/dist/remark-mdx-files-Buvxc-sa.d.ts +54 -0
- package/dist/remark-mdx-mermaid-C1bCHHc6.d.ts +15 -0
- package/dist/remark-npm-BbpvkJaT.d.ts +31 -0
- package/dist/remark-steps-DqVEo0iq.d.ts +23 -0
- package/dist/remark-structure-CnHwvNZr.d.ts +87 -0
- package/dist/remove-markdown-DfKNMl9w.js +40 -0
- package/dist/remove-undefined-CzMSKybq.js +24 -0
- package/dist/rolldown-runtime-DC62tzP2.js +33 -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 +53 -0
- package/dist/search/client/fetch.d.ts +2 -0
- package/dist/search/client/fetch.js +28 -0
- package/dist/search/client/flexsearch-static.d.ts +2 -0
- package/dist/search/client/flexsearch-static.js +42 -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 +75 -0
- package/dist/search/client.d.ts +2 -0
- package/dist/search/client.js +97 -0
- package/dist/search/flexsearch.d.ts +56 -0
- package/dist/search/flexsearch.js +128 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +74 -0
- package/dist/search/mixedbread.d.ts +49 -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 +237 -0
- package/dist/server-CCqACwlF.d.ts +165 -0
- package/dist/server.browser.d.ts +13 -0
- package/dist/server.browser.js +22 -0
- package/dist/server.d.ts +42 -0
- package/dist/server.js +398 -0
- package/dist/source/client/index.d.ts +2 -0
- package/dist/source/client/index.js +37 -0
- package/dist/source/dynamic.d.ts +2 -0
- package/dist/source/dynamic.js +2 -0
- package/dist/source/index.d.ts +2 -0
- package/dist/source/index.js +5 -0
- package/dist/source/llms.d.ts +2 -0
- package/dist/source/llms.js +74 -0
- package/dist/source/plugins/lucide-icons.d.ts +11 -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 +75 -0
- package/dist/source/plugins/status-badges.d.ts +50 -0
- package/dist/source/plugins/status-badges.js +52 -0
- package/dist/source/schema.d.ts +30 -0
- package/dist/source/schema.js +28 -0
- package/dist/stringifier-B_QUcUyo.d.ts +63 -0
- package/dist/toc-CtW5lwA1.d.ts +64 -0
- package/dist/toc.d.ts +2 -0
- package/dist/toc.js +245 -0
- package/dist/transformer-icon-DlrneIS3.d.ts +17 -0
- package/dist/types-D89QoQR-.d.ts +4 -0
- package/dist/url-BVHvi3_K.js +29 -0
- package/dist/util-BDsqOxh3.d.ts +6 -0
- package/dist/util-DjBr9b3w.js +8 -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 +17 -0
- package/dist/utils-Bvy3V-fv.js +59 -0
- package/dist/utils-Cgs-6U-z.js +39 -0
- package/dist/utils-DEVq3cEC.js +151 -0
- package/dist/utils-Yx0IL9eW.js +48 -0
- package/package.json +251 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { t as Awaitable } from "../types-D89QoQR-.js";
|
|
2
|
+
import { n as I18nConfig } from "../index-DydiXvgS.js";
|
|
3
|
+
import "../index-BM36H-xw.js";
|
|
4
|
+
import { m as SharedIndex, n as SearchAPI, t as QueryOptions } from "../server-CCqACwlF.js";
|
|
5
|
+
import { b as LoaderOutput, v as LoaderConfig } from "../index-DIwKCYOz.js";
|
|
6
|
+
import { DocumentData, DocumentOptions } from "flexsearch";
|
|
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
|
+
locale?: string;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/search/flexsearch/utils.d.ts
|
|
20
|
+
type Doc = SharedDocument & DocumentData;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/search/flexsearch.d.ts
|
|
23
|
+
type Index = SharedIndex;
|
|
24
|
+
interface IndexWithLocale extends Index {
|
|
25
|
+
locale: string;
|
|
26
|
+
}
|
|
27
|
+
interface Options {
|
|
28
|
+
indexes: Index[] | (() => Awaitable<Index[]>);
|
|
29
|
+
document?: DocumentOptions<Doc>;
|
|
30
|
+
}
|
|
31
|
+
type ExportedData = {
|
|
32
|
+
type: 'default';
|
|
33
|
+
raw: Record<string, string>;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'i18n';
|
|
36
|
+
raw: Record<string, Record<string, string>>;
|
|
37
|
+
};
|
|
38
|
+
interface I18nOptions extends Omit<Options, 'indexes'> {
|
|
39
|
+
i18n: I18nConfig;
|
|
40
|
+
indexes: IndexWithLocale[] | (() => Awaitable<IndexWithLocale[]>);
|
|
41
|
+
/**
|
|
42
|
+
* options for each locale, see https://github.com/nextapps-de/flexsearch/blob/master/doc/encoder.md.
|
|
43
|
+
*/
|
|
44
|
+
localeMap?: Record<string, Partial<DocumentOptions<Doc>> | 'cjk'>;
|
|
45
|
+
}
|
|
46
|
+
declare function flexsearch(options: Options): SearchAPI;
|
|
47
|
+
declare function flexsearchI18n(options: I18nOptions): SearchAPI;
|
|
48
|
+
interface FromSourceOptions<C extends LoaderConfig> extends Pick<I18nOptions, 'localeMap' | 'document'> {
|
|
49
|
+
buildIndex?: (page: C['page']) => Awaitable<Index>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* create server from loader, if passed as function, the server will re-index all records once a different instance of loader is returned.
|
|
53
|
+
*/
|
|
54
|
+
declare function flexsearchFromSource<C extends LoaderConfig>(loader: LoaderOutput<C> | (() => Awaitable<LoaderOutput<C>>), options?: FromSourceOptions<NoInfer<C>>): SearchAPI<QueryOptions>;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { ExportedData, FromSourceOptions, I18nOptions, Index, IndexWithLocale, Options, flexsearch, flexsearchFromSource, flexsearchI18n };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { t as createEndpoint } from "../endpoint-MyoBU5IC.js";
|
|
2
|
+
import { n as buildBreadcrumbs, r as buildIndexDefault, t as buildDocuments } from "../build-doc-4OvfjVN2.js";
|
|
3
|
+
import { n as search, t as createDocument } from "../utils-Bvy3V-fv.js";
|
|
4
|
+
import Search from "flexsearch";
|
|
5
|
+
//#region src/search/flexsearch.ts
|
|
6
|
+
function server(options) {
|
|
7
|
+
function initIndex(indexes) {
|
|
8
|
+
const index = createDocument(options.document);
|
|
9
|
+
for (const doc of buildDocuments(indexes)) index.add(doc.id, doc);
|
|
10
|
+
return index;
|
|
11
|
+
}
|
|
12
|
+
const indexPromise = typeof options.indexes === "function" ? Promise.resolve(options.indexes()).then(initIndex) : initIndex(options.indexes);
|
|
13
|
+
return {
|
|
14
|
+
async export() {
|
|
15
|
+
const index = await indexPromise;
|
|
16
|
+
const raw = {};
|
|
17
|
+
index.export((key, data) => {
|
|
18
|
+
raw[key] = data;
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
type: "default",
|
|
22
|
+
raw
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
async search(query, searchOptions) {
|
|
26
|
+
return search(await indexPromise, query, searchOptions?.tag, searchOptions?.limit);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function serverI18n(options) {
|
|
31
|
+
const { indexes: inputIndexes, localeMap } = options;
|
|
32
|
+
async function initSearchServers() {
|
|
33
|
+
const map = /* @__PURE__ */ new Map();
|
|
34
|
+
const indexMap = /* @__PURE__ */ new Map();
|
|
35
|
+
const indexes = typeof inputIndexes === "function" ? await inputIndexes() : inputIndexes;
|
|
36
|
+
for (const index of indexes) {
|
|
37
|
+
let list = indexMap.get(index.locale);
|
|
38
|
+
if (!list) {
|
|
39
|
+
list = [];
|
|
40
|
+
indexMap.set(index.locale, list);
|
|
41
|
+
}
|
|
42
|
+
list.push(index);
|
|
43
|
+
}
|
|
44
|
+
for (const [locale, list] of indexMap) {
|
|
45
|
+
const override = localeMap?.[locale];
|
|
46
|
+
map.set(locale, server({
|
|
47
|
+
indexes: list,
|
|
48
|
+
document: override === "cjk" ? {
|
|
49
|
+
...options.document,
|
|
50
|
+
encoder: Search.Charset.CJK
|
|
51
|
+
} : {
|
|
52
|
+
...options.document,
|
|
53
|
+
...override
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
return map;
|
|
58
|
+
}
|
|
59
|
+
const get = initSearchServers();
|
|
60
|
+
return {
|
|
61
|
+
async export() {
|
|
62
|
+
const map = await get;
|
|
63
|
+
const entries = Array.from(map.entries()).map(async ([k, v]) => {
|
|
64
|
+
return [k, (await v.export()).raw];
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
type: "i18n",
|
|
68
|
+
raw: Object.fromEntries(await Promise.all(entries))
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
async search(query, searchOptions) {
|
|
72
|
+
const handler = (await get).get(searchOptions?.locale ?? options.i18n.defaultLanguage);
|
|
73
|
+
if (handler) return handler.search(query, searchOptions);
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function flexsearch(options) {
|
|
79
|
+
return createEndpoint(server(options));
|
|
80
|
+
}
|
|
81
|
+
function flexsearchI18n(options) {
|
|
82
|
+
return createEndpoint(serverI18n(options));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* create server from loader, if passed as function, the server will re-index all records once a different instance of loader is returned.
|
|
86
|
+
*/
|
|
87
|
+
function flexsearchFromSource(loader, options = {}) {
|
|
88
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
89
|
+
const { buildIndex = buildIndexDefault, ...rest } = options;
|
|
90
|
+
async function initServer(loader) {
|
|
91
|
+
const indexes = await Promise.all(loader.getPages().map(async (page) => {
|
|
92
|
+
const index = await buildIndex(page);
|
|
93
|
+
return {
|
|
94
|
+
...index,
|
|
95
|
+
locale: page.locale,
|
|
96
|
+
breadcrumbs: index.breadcrumbs ?? buildBreadcrumbs(loader, page)
|
|
97
|
+
};
|
|
98
|
+
}));
|
|
99
|
+
if (loader._i18n) return serverI18n({
|
|
100
|
+
indexes,
|
|
101
|
+
i18n: loader._i18n,
|
|
102
|
+
...rest
|
|
103
|
+
});
|
|
104
|
+
return server({
|
|
105
|
+
indexes,
|
|
106
|
+
...rest
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function getCurrentServer() {
|
|
110
|
+
const l = typeof loader === "function" ? await loader() : loader;
|
|
111
|
+
let server = cache.get(l);
|
|
112
|
+
if (!server) {
|
|
113
|
+
server = initServer(l);
|
|
114
|
+
cache.set(l, server);
|
|
115
|
+
}
|
|
116
|
+
return await server;
|
|
117
|
+
}
|
|
118
|
+
return createEndpoint({
|
|
119
|
+
async export() {
|
|
120
|
+
return (await getCurrentServer()).export();
|
|
121
|
+
},
|
|
122
|
+
async search(query, options) {
|
|
123
|
+
return (await getCurrentServer()).search(query, options);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { flexsearch, flexsearchFromSource, flexsearchI18n };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { remark } from "remark";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
//#region src/search/index.ts
|
|
4
|
+
function escapeRegExp(input) {
|
|
5
|
+
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6
|
+
}
|
|
7
|
+
function buildRegexFromQuery(q) {
|
|
8
|
+
const trimmed = q.trim();
|
|
9
|
+
if (trimmed.length === 0) return null;
|
|
10
|
+
const terms = Array.from(new Set(trimmed.split(/\s+/).filter(Boolean)));
|
|
11
|
+
if (terms.length === 0) return null;
|
|
12
|
+
const escaped = terms.map(escapeRegExp).join("|");
|
|
13
|
+
return new RegExp(`(${escaped})`, "gi");
|
|
14
|
+
}
|
|
15
|
+
const processor = remark();
|
|
16
|
+
function createContentHighlighter(query) {
|
|
17
|
+
const regex = typeof query === "string" ? buildRegexFromQuery(query) : query;
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use `highlightMarkdown()` instead.
|
|
21
|
+
*/
|
|
22
|
+
highlight(content) {
|
|
23
|
+
if (!regex) return [{
|
|
24
|
+
type: "text",
|
|
25
|
+
content
|
|
26
|
+
}];
|
|
27
|
+
const out = [];
|
|
28
|
+
let i = 0;
|
|
29
|
+
for (const match of content.matchAll(regex)) {
|
|
30
|
+
if (i < match.index) out.push({
|
|
31
|
+
type: "text",
|
|
32
|
+
content: content.substring(i, match.index)
|
|
33
|
+
});
|
|
34
|
+
out.push({
|
|
35
|
+
type: "text",
|
|
36
|
+
content: match[0],
|
|
37
|
+
styles: { highlight: true }
|
|
38
|
+
});
|
|
39
|
+
i = match.index + match[0].length;
|
|
40
|
+
}
|
|
41
|
+
if (i < content.length) out.push({
|
|
42
|
+
type: "text",
|
|
43
|
+
content: content.substring(i)
|
|
44
|
+
});
|
|
45
|
+
return out;
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* @param content - Markdown, it assumes the content is already sanitized & safe, no escape is performed.
|
|
49
|
+
*/
|
|
50
|
+
highlightMarkdown(content) {
|
|
51
|
+
if (!regex) return content;
|
|
52
|
+
const tree = processor.parse(content);
|
|
53
|
+
highlightInTree(tree, regex);
|
|
54
|
+
return processor.stringify(tree).trim();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function highlightInTree(tree, regex) {
|
|
59
|
+
visit(tree, "text", (node) => {
|
|
60
|
+
let out = "";
|
|
61
|
+
const content = node.value;
|
|
62
|
+
let i = 0;
|
|
63
|
+
for (const match of content.matchAll(regex)) {
|
|
64
|
+
if (i < match.index) out += content.substring(i, match.index);
|
|
65
|
+
out += `<mark>${match[0]}</mark>`;
|
|
66
|
+
i = match.index + match[0].length;
|
|
67
|
+
}
|
|
68
|
+
if (i < content.length) out += content.substring(i);
|
|
69
|
+
node.type = "html";
|
|
70
|
+
node.value = out;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { createContentHighlighter };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { r as SortedResult } from "../index-BM36H-xw.js";
|
|
2
|
+
import { n as SearchAPI } from "../server-CCqACwlF.js";
|
|
3
|
+
import Mixedbread from "@mixedbread/sdk";
|
|
4
|
+
import { StoreSearchResponse } from "@mixedbread/sdk/resources/stores";
|
|
5
|
+
//#region src/search/mixedbread.d.ts
|
|
6
|
+
interface SearchMetadata {
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
tag?: string;
|
|
11
|
+
}
|
|
12
|
+
type StoreSearchResult = StoreSearchResponse['data'][number] & {
|
|
13
|
+
generated_metadata: SearchMetadata;
|
|
14
|
+
};
|
|
15
|
+
interface MixedbreadSearchOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The Mixedbread SDK client instance
|
|
18
|
+
*/
|
|
19
|
+
client: Mixedbread;
|
|
20
|
+
/**
|
|
21
|
+
* The identifier of the store to search in
|
|
22
|
+
*/
|
|
23
|
+
storeIdentifier: string;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum number of results to return
|
|
26
|
+
*
|
|
27
|
+
* @defaultValue 10
|
|
28
|
+
*/
|
|
29
|
+
topK?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Re-rank search results for improved relevance (this adds latency to the search)
|
|
32
|
+
*/
|
|
33
|
+
rerank?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Rewrite the query for better search results (this adds latency to the search)
|
|
36
|
+
*/
|
|
37
|
+
rewriteQuery?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Minimum score threshold for results
|
|
40
|
+
*/
|
|
41
|
+
scoreThreshold?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Custom transform function for search results
|
|
44
|
+
*/
|
|
45
|
+
transform?: (results: StoreSearchResult[], query: string) => SortedResult[];
|
|
46
|
+
}
|
|
47
|
+
declare function createMixedbreadSearchAPI(options: MixedbreadSearchOptions): SearchAPI;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { MixedbreadSearchOptions, SearchMetadata, createMixedbreadSearchAPI };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { r as __toESM } from "../rolldown-runtime-DC62tzP2.js";
|
|
2
|
+
import { t as createEndpoint } from "../endpoint-MyoBU5IC.js";
|
|
3
|
+
import { t as require_remove_markdown } from "../remove-markdown-DfKNMl9w.js";
|
|
4
|
+
import Slugger from "github-slugger";
|
|
5
|
+
//#region src/search/mixedbread.ts
|
|
6
|
+
var import_remove_markdown = /* @__PURE__ */ __toESM(require_remove_markdown(), 1);
|
|
7
|
+
const slugger = new Slugger();
|
|
8
|
+
function extractHeadingTitle(text) {
|
|
9
|
+
const trimmedText = text.trim();
|
|
10
|
+
if (!trimmedText.startsWith("#")) return "";
|
|
11
|
+
const firstLine = trimmedText.split("\n")[0]?.trim();
|
|
12
|
+
if (firstLine) return (0, import_remove_markdown.default)(firstLine, { useImgAltText: false });
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
function defaultTransform(results) {
|
|
16
|
+
return results.flatMap((item) => {
|
|
17
|
+
const metadata = item.generated_metadata;
|
|
18
|
+
const url = metadata.url || "#";
|
|
19
|
+
const title = metadata.title || "Untitled";
|
|
20
|
+
const chunkResults = [{
|
|
21
|
+
id: `${item.file_id}-${item.chunk_index}-page`,
|
|
22
|
+
type: "page",
|
|
23
|
+
content: title,
|
|
24
|
+
url
|
|
25
|
+
}];
|
|
26
|
+
const headingTitle = item.type === "text" && item.text ? extractHeadingTitle(item.text) : "";
|
|
27
|
+
if (headingTitle) {
|
|
28
|
+
slugger.reset();
|
|
29
|
+
chunkResults.push({
|
|
30
|
+
id: `${item.file_id}-${item.chunk_index}-heading`,
|
|
31
|
+
type: "heading",
|
|
32
|
+
content: headingTitle,
|
|
33
|
+
url: `${url}#${slugger.slug(headingTitle)}`
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return chunkResults;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function createMixedbreadSearchAPI(options) {
|
|
40
|
+
const { client, storeIdentifier, topK = 10, rerank, rewriteQuery, scoreThreshold, transform } = options;
|
|
41
|
+
return createEndpoint({
|
|
42
|
+
async search(query, searchOptions = {}) {
|
|
43
|
+
if (!query.trim()) return [];
|
|
44
|
+
const { tag, limit } = searchOptions;
|
|
45
|
+
let filters;
|
|
46
|
+
if (Array.isArray(tag) && tag.length > 0) filters = {
|
|
47
|
+
key: "generated_metadata.tag",
|
|
48
|
+
operator: "in",
|
|
49
|
+
value: tag
|
|
50
|
+
};
|
|
51
|
+
else if (typeof tag === "string") filters = {
|
|
52
|
+
key: "generated_metadata.tag",
|
|
53
|
+
operator: "eq",
|
|
54
|
+
value: tag
|
|
55
|
+
};
|
|
56
|
+
const results = (await client.stores.search({
|
|
57
|
+
query,
|
|
58
|
+
store_identifiers: [storeIdentifier],
|
|
59
|
+
top_k: limit ?? topK,
|
|
60
|
+
filters,
|
|
61
|
+
search_options: {
|
|
62
|
+
return_metadata: true,
|
|
63
|
+
rerank,
|
|
64
|
+
rewrite_query: rewriteQuery,
|
|
65
|
+
score_threshold: scoreThreshold
|
|
66
|
+
}
|
|
67
|
+
})).data;
|
|
68
|
+
if (transform) return transform(results, query);
|
|
69
|
+
return defaultTransform(results);
|
|
70
|
+
},
|
|
71
|
+
async export() {
|
|
72
|
+
throw new Error("Mixedbread search does not support exporting indexes. Use the Mixedbread dashboard to manage your store.");
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { createMixedbreadSearchAPI };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { i as StructuredData } from "../remark-structure-CnHwvNZr.js";
|
|
2
|
+
import "../index-DAYtLGbx.js";
|
|
3
|
+
import { CloudManager } from "@oramacloud/client";
|
|
4
|
+
//#region src/search/orama-cloud-legacy.d.ts
|
|
5
|
+
interface SyncOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Index name to sync
|
|
8
|
+
*/
|
|
9
|
+
index: string;
|
|
10
|
+
documents: OramaDocument[];
|
|
11
|
+
/**
|
|
12
|
+
* Deploy changes
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue true
|
|
15
|
+
*/
|
|
16
|
+
autoDeploy?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface I18nSyncOptions extends Omit<SyncOptions, 'index' | 'documents'> {
|
|
19
|
+
/**
|
|
20
|
+
* Indexes to sync.
|
|
21
|
+
*
|
|
22
|
+
* Pairs of `locale`-`index`.
|
|
23
|
+
**/
|
|
24
|
+
indexes: Record<string, string>;
|
|
25
|
+
documents: {
|
|
26
|
+
locale: string;
|
|
27
|
+
items: OramaDocument[];
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
interface OramaDocument {
|
|
31
|
+
/**
|
|
32
|
+
* The ID of document, must be unique
|
|
33
|
+
*/
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
/**
|
|
38
|
+
* URL to the page
|
|
39
|
+
*/
|
|
40
|
+
url: string;
|
|
41
|
+
structured: StructuredData;
|
|
42
|
+
/**
|
|
43
|
+
* Tag to filter results
|
|
44
|
+
*/
|
|
45
|
+
tag?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Data to be added to each section index
|
|
48
|
+
*/
|
|
49
|
+
extra_data?: object;
|
|
50
|
+
breadcrumbs?: string[];
|
|
51
|
+
}
|
|
52
|
+
interface OramaIndex {
|
|
53
|
+
id: string;
|
|
54
|
+
title: string;
|
|
55
|
+
url: string;
|
|
56
|
+
tag?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The id of page, used for `group by`
|
|
59
|
+
*/
|
|
60
|
+
page_id: string;
|
|
61
|
+
/**
|
|
62
|
+
* Heading content
|
|
63
|
+
*/
|
|
64
|
+
section?: string;
|
|
65
|
+
breadcrumbs?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Heading (anchor) id
|
|
68
|
+
*/
|
|
69
|
+
section_id?: string;
|
|
70
|
+
content: string;
|
|
71
|
+
}
|
|
72
|
+
declare function sync(cloudManager: CloudManager, options: SyncOptions): Promise<void>;
|
|
73
|
+
declare function syncI18n(cloudManager: CloudManager, options: I18nSyncOptions): Promise<void>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { I18nSyncOptions, OramaDocument, OramaIndex, SyncOptions, sync, syncI18n };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/search/orama-cloud-legacy.ts
|
|
2
|
+
async function sync(cloudManager, options) {
|
|
3
|
+
const { autoDeploy = true } = options;
|
|
4
|
+
const index = cloudManager.index(options.index);
|
|
5
|
+
await index.snapshot(options.documents.flatMap(toIndex));
|
|
6
|
+
if (autoDeploy) await index.deploy();
|
|
7
|
+
}
|
|
8
|
+
async function syncI18n(cloudManager, options) {
|
|
9
|
+
const { autoDeploy = true } = options;
|
|
10
|
+
const tasks = options.documents.map(async (document) => {
|
|
11
|
+
const index = cloudManager.index(options.indexes[document.locale]);
|
|
12
|
+
await index.snapshot(document.items.flatMap(toIndex));
|
|
13
|
+
if (autoDeploy) await index.deploy();
|
|
14
|
+
});
|
|
15
|
+
await Promise.all(tasks);
|
|
16
|
+
}
|
|
17
|
+
function toIndex(page) {
|
|
18
|
+
let id = 0;
|
|
19
|
+
const indexes = [];
|
|
20
|
+
const scannedHeadings = /* @__PURE__ */ new Set();
|
|
21
|
+
function createIndex(section, sectionId, content) {
|
|
22
|
+
return {
|
|
23
|
+
id: `${page.id}-${(id++).toString()}`,
|
|
24
|
+
title: page.title,
|
|
25
|
+
url: page.url,
|
|
26
|
+
page_id: page.id,
|
|
27
|
+
tag: page.tag,
|
|
28
|
+
section,
|
|
29
|
+
section_id: sectionId,
|
|
30
|
+
content,
|
|
31
|
+
breadcrumbs: page.breadcrumbs,
|
|
32
|
+
...page.extra_data
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (page.description) indexes.push(createIndex(void 0, void 0, page.description));
|
|
36
|
+
page.structured.contents.forEach((p) => {
|
|
37
|
+
const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
|
|
38
|
+
const index = createIndex(heading?.content, heading?.id, p.content);
|
|
39
|
+
if (heading && !scannedHeadings.has(heading.id)) {
|
|
40
|
+
scannedHeadings.add(heading.id);
|
|
41
|
+
indexes.push(createIndex(heading.content, heading.id, heading.content));
|
|
42
|
+
}
|
|
43
|
+
indexes.push(index);
|
|
44
|
+
});
|
|
45
|
+
return indexes;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { sync, syncI18n };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { i as StructuredData } from "../remark-structure-CnHwvNZr.js";
|
|
2
|
+
import "../index-DAYtLGbx.js";
|
|
3
|
+
import { OramaCloud } from "@orama/core";
|
|
4
|
+
//#region src/search/orama-cloud.d.ts
|
|
5
|
+
interface SyncOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Index name to sync
|
|
8
|
+
*/
|
|
9
|
+
index: string;
|
|
10
|
+
documents: OramaDocument[];
|
|
11
|
+
/**
|
|
12
|
+
* Deploy changes
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue true
|
|
15
|
+
*/
|
|
16
|
+
autoDeploy?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface I18nSyncOptions extends Omit<SyncOptions, 'index' | 'documents'> {
|
|
19
|
+
/**
|
|
20
|
+
* Indexes to sync.
|
|
21
|
+
*
|
|
22
|
+
* Pairs of `locale`-`index`.
|
|
23
|
+
**/
|
|
24
|
+
indexes: Record<string, string>;
|
|
25
|
+
documents: {
|
|
26
|
+
locale: string;
|
|
27
|
+
items: OramaDocument[];
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
interface OramaDocument {
|
|
31
|
+
/**
|
|
32
|
+
* The ID of document, must be unique
|
|
33
|
+
*/
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
/**
|
|
38
|
+
* URL to the page
|
|
39
|
+
*/
|
|
40
|
+
url: string;
|
|
41
|
+
structured: StructuredData;
|
|
42
|
+
/**
|
|
43
|
+
* Tag to filter results
|
|
44
|
+
*/
|
|
45
|
+
tag?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Data to be added to each section index
|
|
48
|
+
*/
|
|
49
|
+
extra_data?: object;
|
|
50
|
+
breadcrumbs?: string[];
|
|
51
|
+
}
|
|
52
|
+
interface OramaIndex {
|
|
53
|
+
id: string;
|
|
54
|
+
title: string;
|
|
55
|
+
url: string;
|
|
56
|
+
tag?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The id of page, used for `group by`
|
|
59
|
+
*/
|
|
60
|
+
page_id: string;
|
|
61
|
+
/**
|
|
62
|
+
* Heading content
|
|
63
|
+
*/
|
|
64
|
+
section?: string;
|
|
65
|
+
breadcrumbs?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Heading (anchor) id
|
|
68
|
+
*/
|
|
69
|
+
section_id?: string;
|
|
70
|
+
content: string;
|
|
71
|
+
}
|
|
72
|
+
declare function sync(orama: OramaCloud, options: SyncOptions): Promise<void>;
|
|
73
|
+
declare function syncI18n(orama: OramaCloud, options: I18nSyncOptions): Promise<void>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { I18nSyncOptions, OramaDocument, OramaIndex, SyncOptions, sync, syncI18n };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/search/orama-cloud.ts
|
|
2
|
+
async function sync(orama, options) {
|
|
3
|
+
const { autoDeploy = true } = options;
|
|
4
|
+
const index = orama.index.set(options.index);
|
|
5
|
+
await index.transaction.open();
|
|
6
|
+
await index.transaction.insertDocuments(options.documents.flatMap(toIndex));
|
|
7
|
+
if (autoDeploy) await index.transaction.commit();
|
|
8
|
+
}
|
|
9
|
+
async function syncI18n(orama, options) {
|
|
10
|
+
const { autoDeploy = true, indexes } = options;
|
|
11
|
+
const tasks = options.documents.map(async (document) => {
|
|
12
|
+
const index = orama.index.set(indexes[document.locale]);
|
|
13
|
+
await index.transaction.open();
|
|
14
|
+
await index.transaction.insertDocuments(document.items.flatMap(toIndex));
|
|
15
|
+
if (autoDeploy) await index.transaction.commit();
|
|
16
|
+
});
|
|
17
|
+
await Promise.all(tasks);
|
|
18
|
+
}
|
|
19
|
+
function toIndex(page) {
|
|
20
|
+
let id = 0;
|
|
21
|
+
const indexes = [];
|
|
22
|
+
const scannedHeadings = /* @__PURE__ */ new Set();
|
|
23
|
+
function createIndex(section, sectionId, content) {
|
|
24
|
+
return {
|
|
25
|
+
id: `${page.id}-${(id++).toString()}`,
|
|
26
|
+
title: page.title,
|
|
27
|
+
url: page.url,
|
|
28
|
+
page_id: page.id,
|
|
29
|
+
tag: page.tag,
|
|
30
|
+
section,
|
|
31
|
+
section_id: sectionId,
|
|
32
|
+
content,
|
|
33
|
+
breadcrumbs: page.breadcrumbs,
|
|
34
|
+
...page.extra_data
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (page.description) indexes.push(createIndex(void 0, void 0, page.description));
|
|
38
|
+
page.structured.contents.forEach((p) => {
|
|
39
|
+
const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
|
|
40
|
+
const index = createIndex(heading?.content, heading?.id, p.content);
|
|
41
|
+
if (heading && !scannedHeadings.has(heading.id)) {
|
|
42
|
+
scannedHeadings.add(heading.id);
|
|
43
|
+
indexes.push(createIndex(heading.content, heading.id, heading.content));
|
|
44
|
+
}
|
|
45
|
+
indexes.push(index);
|
|
46
|
+
});
|
|
47
|
+
return indexes;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { sync, syncI18n };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as AdvancedOptions, c as SimpleOptions, d as createSearchAPI, f as initAdvancedSearch, i as AdvancedIndex, l as createFromSource, n as SearchAPI, o as ExportedData, p as initSimpleSearch, r as SearchServer, s as Index, t as QueryOptions, u as createI18nSearchAPI } from "../server-CCqACwlF.js";
|
|
2
|
+
export { AdvancedIndex, AdvancedOptions, ExportedData, Index, QueryOptions, SearchAPI, SearchServer, SimpleOptions, createFromSource, createI18nSearchAPI, createSearchAPI, initAdvancedSearch, initSimpleSearch };
|