fumadocs-core 13.4.10 → 14.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/dist/{search-algolia/client.js → algolia-NTWLS6J3.js} +10 -27
- package/dist/breadcrumb.d.ts +15 -7
- package/dist/breadcrumb.js +47 -25
- package/dist/chunk-2V6SCS43.js +12 -0
- package/dist/chunk-2ZSMGYVH.js +78 -0
- package/dist/{chunk-UQV4A7HQ.js → chunk-4MNUWZIW.js} +9 -7
- package/dist/{chunk-KGMG4N3Y.js → chunk-I5BWASD6.js} +2 -2
- package/dist/dynamic-link.js +2 -1
- package/dist/fetch-4K7QOPFM.js +17 -0
- package/dist/i18n/index.js +64 -3
- package/dist/mdx-plugins/index.d.ts +20 -5
- package/dist/mdx-plugins/index.js +143 -17
- package/dist/{page-tree-BTCDMLTU.d.ts → page-tree-r8qjoUla.d.ts} +7 -4
- package/dist/{search-algolia/server.d.ts → search/algolia.d.ts} +1 -1
- package/dist/{search-algolia/server.js → search/algolia.js} +1 -1
- package/dist/search/client.d.ts +37 -7
- package/dist/search/client.js +74 -22
- package/dist/search/server.d.ts +65 -32
- package/dist/search/server.js +272 -234
- package/dist/server/index.d.ts +56 -4
- package/dist/server/index.js +59 -1
- package/dist/sidebar.js +7 -5
- package/dist/source/index.d.ts +14 -23
- package/dist/source/index.js +89 -81
- package/dist/static-5GPJ7RUY.js +60 -0
- package/dist/toc.js +1 -1
- package/dist/{search/shared.d.ts → types-Ch8gnVgO.d.ts} +1 -1
- package/dist/utils/use-on-change.d.ts +6 -1
- package/dist/utils/use-on-change.js +1 -1
- package/package.json +27 -86
- package/dist/chunk-MXOJWF66.js +0 -67
- package/dist/chunk-NREWOIVI.js +0 -19
- package/dist/middleware.d.ts +0 -3
- package/dist/middleware.js +0 -7
- package/dist/search/shared.js +0 -0
- package/dist/search-algolia/client.d.ts +0 -37
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flattenNode,
|
|
3
|
-
remarkHeading
|
|
4
|
-
} from "../chunk-UQV4A7HQ.js";
|
|
5
1
|
import {
|
|
6
2
|
slash
|
|
7
3
|
} from "../chunk-UWEEHUJV.js";
|
|
4
|
+
import {
|
|
5
|
+
flattenNode,
|
|
6
|
+
remarkHeading
|
|
7
|
+
} from "../chunk-4MNUWZIW.js";
|
|
8
8
|
import "../chunk-MLKGABMK.js";
|
|
9
9
|
|
|
10
10
|
// src/mdx-plugins/index.ts
|
|
@@ -15,15 +15,16 @@ import {
|
|
|
15
15
|
// src/mdx-plugins/rehype-code.ts
|
|
16
16
|
import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
|
|
17
17
|
import {
|
|
18
|
+
transformerNotationDiff,
|
|
18
19
|
transformerNotationHighlight,
|
|
19
20
|
transformerNotationWordHighlight
|
|
20
21
|
} from "@shikijs/transformers";
|
|
21
22
|
import {
|
|
22
23
|
getSingletonHighlighter,
|
|
23
|
-
createJavaScriptRegexEngine,
|
|
24
|
-
createWasmOnigEngine,
|
|
25
24
|
bundledLanguages
|
|
26
25
|
} from "shiki";
|
|
26
|
+
import { createOnigurumaEngine } from "shiki/engine/oniguruma";
|
|
27
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
27
28
|
|
|
28
29
|
// src/mdx-plugins/transformer-icon.ts
|
|
29
30
|
var defaultShortcuts = {
|
|
@@ -193,7 +194,8 @@ var rehypeCodeDefaultOptions = {
|
|
|
193
194
|
defaultColor: false,
|
|
194
195
|
transformers: [
|
|
195
196
|
transformerNotationHighlight(),
|
|
196
|
-
transformerNotationWordHighlight()
|
|
197
|
+
transformerNotationWordHighlight(),
|
|
198
|
+
transformerNotationDiff()
|
|
197
199
|
],
|
|
198
200
|
parseMetaString(meta) {
|
|
199
201
|
const map = {};
|
|
@@ -255,22 +257,22 @@ function rehypeCode(options = {}) {
|
|
|
255
257
|
themeItems = [codeOptions.theme];
|
|
256
258
|
}
|
|
257
259
|
const highlighter = getSingletonHighlighter({
|
|
258
|
-
engine: codeOptions.experimentalJSEngine ? createJavaScriptRegexEngine() :
|
|
260
|
+
engine: codeOptions.experimentalJSEngine ? createJavaScriptRegexEngine() : createOnigurumaEngine(() => import("shiki/wasm")),
|
|
259
261
|
themes: themeItems.filter(Boolean),
|
|
260
262
|
langs: codeOptions.langs ?? Object.keys(bundledLanguages)
|
|
261
263
|
});
|
|
264
|
+
const transformer = highlighter.then(
|
|
265
|
+
(instance) => rehypeShikiFromHighlighter(instance, codeOptions)
|
|
266
|
+
);
|
|
262
267
|
return async (tree, file) => {
|
|
263
|
-
|
|
264
|
-
await highlighter,
|
|
265
|
-
codeOptions
|
|
266
|
-
);
|
|
267
|
-
await transformer(tree, file, () => {
|
|
268
|
+
await (await transformer)(tree, file, () => {
|
|
268
269
|
});
|
|
269
270
|
};
|
|
270
271
|
}
|
|
271
272
|
function transformerTab() {
|
|
272
273
|
return {
|
|
273
274
|
name: "rehype-code:tab",
|
|
275
|
+
// @ts-expect-error -- types not compatible with MDX
|
|
274
276
|
root(root) {
|
|
275
277
|
const meta = this.options.meta;
|
|
276
278
|
if (typeof meta?.tab !== "string") return root;
|
|
@@ -295,7 +297,7 @@ function transformerTab() {
|
|
|
295
297
|
}
|
|
296
298
|
|
|
297
299
|
// src/mdx-plugins/remark-image.ts
|
|
298
|
-
import path from "path";
|
|
300
|
+
import path from "node:path";
|
|
299
301
|
import { visit } from "unist-util-visit";
|
|
300
302
|
import sizeOf from "image-size";
|
|
301
303
|
var VALID_BLUR_EXT = [".jpeg", ".png", ".webp", ".avif", ".jpg"];
|
|
@@ -443,7 +445,6 @@ async function getImageSize(src, dir) {
|
|
|
443
445
|
import Slugger from "github-slugger";
|
|
444
446
|
import { remark } from "remark";
|
|
445
447
|
import remarkGfm from "remark-gfm";
|
|
446
|
-
import remarkMdx from "remark-mdx";
|
|
447
448
|
import { visit as visit2 } from "unist-util-visit";
|
|
448
449
|
var slugger = new Slugger();
|
|
449
450
|
function remarkStructure({
|
|
@@ -487,7 +488,7 @@ function remarkStructure({
|
|
|
487
488
|
};
|
|
488
489
|
}
|
|
489
490
|
function structure(content, remarkPlugins = [], options = {}) {
|
|
490
|
-
const result = remark().use(remarkGfm).use(
|
|
491
|
+
const result = remark().use(remarkGfm).use(remarkPlugins).use(remarkStructure, options).processSync(content);
|
|
491
492
|
return result.data.structuredData;
|
|
492
493
|
}
|
|
493
494
|
|
|
@@ -554,14 +555,139 @@ function remarkAdmonition(options = {}) {
|
|
|
554
555
|
});
|
|
555
556
|
};
|
|
556
557
|
}
|
|
558
|
+
|
|
559
|
+
// src/mdx-plugins/rehype-toc.ts
|
|
560
|
+
import { toEstree } from "hast-util-to-estree";
|
|
561
|
+
|
|
562
|
+
// src/mdx-plugins/hast-utils.ts
|
|
563
|
+
function visit4(node, tagNames, handler) {
|
|
564
|
+
if (node.type === "element" && tagNames.includes(node.tagName)) {
|
|
565
|
+
const result = handler(node);
|
|
566
|
+
if (result === "skip") return;
|
|
567
|
+
}
|
|
568
|
+
if ("children" in node)
|
|
569
|
+
node.children.forEach((n) => {
|
|
570
|
+
visit4(n, tagNames, handler);
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/mdx-plugins/rehype-toc.ts
|
|
575
|
+
function rehypeToc({ exportToc = true } = {}) {
|
|
576
|
+
return (tree) => {
|
|
577
|
+
const output = [];
|
|
578
|
+
visit4(tree, ["h1", "h2", "h3", "h4", "h5", "h6"], (element) => {
|
|
579
|
+
const id = element.properties.id;
|
|
580
|
+
if (!id) return "skip";
|
|
581
|
+
const estree = toEstree(element, {
|
|
582
|
+
elementAttributeNameCase: "react",
|
|
583
|
+
stylePropertyNameCase: "dom"
|
|
584
|
+
});
|
|
585
|
+
if (estree.body[0].type === "ExpressionStatement")
|
|
586
|
+
output.push({
|
|
587
|
+
title: estree.body[0].expression,
|
|
588
|
+
depth: Number(element.tagName.slice(1)),
|
|
589
|
+
url: `#${id}`
|
|
590
|
+
});
|
|
591
|
+
return "skip";
|
|
592
|
+
});
|
|
593
|
+
const declaration = {
|
|
594
|
+
type: "VariableDeclaration",
|
|
595
|
+
kind: "const",
|
|
596
|
+
declarations: [
|
|
597
|
+
{
|
|
598
|
+
type: "VariableDeclarator",
|
|
599
|
+
id: {
|
|
600
|
+
type: "Identifier",
|
|
601
|
+
name: "toc"
|
|
602
|
+
},
|
|
603
|
+
init: {
|
|
604
|
+
type: "ArrayExpression",
|
|
605
|
+
elements: output.map((item) => ({
|
|
606
|
+
type: "ObjectExpression",
|
|
607
|
+
properties: [
|
|
608
|
+
{
|
|
609
|
+
type: "Property",
|
|
610
|
+
method: false,
|
|
611
|
+
shorthand: false,
|
|
612
|
+
computed: false,
|
|
613
|
+
key: {
|
|
614
|
+
type: "Identifier",
|
|
615
|
+
name: "depth"
|
|
616
|
+
},
|
|
617
|
+
value: {
|
|
618
|
+
type: "Literal",
|
|
619
|
+
value: item.depth
|
|
620
|
+
},
|
|
621
|
+
kind: "init"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
type: "Property",
|
|
625
|
+
method: false,
|
|
626
|
+
shorthand: false,
|
|
627
|
+
computed: false,
|
|
628
|
+
key: {
|
|
629
|
+
type: "Identifier",
|
|
630
|
+
name: "url"
|
|
631
|
+
},
|
|
632
|
+
value: {
|
|
633
|
+
type: "Literal",
|
|
634
|
+
value: item.url
|
|
635
|
+
},
|
|
636
|
+
kind: "init"
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
type: "Property",
|
|
640
|
+
method: false,
|
|
641
|
+
shorthand: false,
|
|
642
|
+
computed: false,
|
|
643
|
+
key: {
|
|
644
|
+
type: "Identifier",
|
|
645
|
+
name: "title"
|
|
646
|
+
},
|
|
647
|
+
value: {
|
|
648
|
+
type: "JSXFragment",
|
|
649
|
+
openingFragment: { type: "JSXOpeningFragment" },
|
|
650
|
+
closingFragment: { type: "JSXClosingFragment" },
|
|
651
|
+
children: item.title.children
|
|
652
|
+
},
|
|
653
|
+
kind: "init"
|
|
654
|
+
}
|
|
655
|
+
]
|
|
656
|
+
}))
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
]
|
|
660
|
+
};
|
|
661
|
+
tree.children.push({
|
|
662
|
+
type: "mdxjsEsm",
|
|
663
|
+
value: "",
|
|
664
|
+
data: {
|
|
665
|
+
estree: {
|
|
666
|
+
type: "Program",
|
|
667
|
+
body: [
|
|
668
|
+
exportToc ? {
|
|
669
|
+
type: "ExportNamedDeclaration",
|
|
670
|
+
declaration,
|
|
671
|
+
specifiers: []
|
|
672
|
+
} : declaration
|
|
673
|
+
],
|
|
674
|
+
sourceType: "module",
|
|
675
|
+
comments: []
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
};
|
|
680
|
+
}
|
|
557
681
|
export {
|
|
558
682
|
rehypeCode,
|
|
559
683
|
rehypeCodeDefaultOptions,
|
|
684
|
+
rehypeToc,
|
|
560
685
|
remarkAdmonition,
|
|
561
686
|
default2 as remarkGfm,
|
|
562
687
|
remarkHeading,
|
|
563
688
|
remarkImage,
|
|
564
689
|
remarkStructure,
|
|
565
690
|
structure,
|
|
566
|
-
transformerIcon
|
|
691
|
+
transformerIcon,
|
|
692
|
+
transformerTab
|
|
567
693
|
};
|
|
@@ -11,18 +11,21 @@ interface Item {
|
|
|
11
11
|
url: string;
|
|
12
12
|
external?: boolean;
|
|
13
13
|
icon?: ReactElement;
|
|
14
|
+
$ref?: {
|
|
15
|
+
file: string;
|
|
16
|
+
};
|
|
14
17
|
}
|
|
15
18
|
interface Separator {
|
|
16
19
|
type: 'separator';
|
|
17
20
|
name: ReactNode;
|
|
18
21
|
}
|
|
19
22
|
interface Folder {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
id?: string;
|
|
23
|
+
$ref?: {
|
|
24
|
+
metaFile?: string;
|
|
25
|
+
};
|
|
24
26
|
type: 'folder';
|
|
25
27
|
name: ReactNode;
|
|
28
|
+
description?: ReactNode;
|
|
26
29
|
root?: boolean;
|
|
27
30
|
defaultOpen?: boolean;
|
|
28
31
|
index?: Item;
|
package/dist/search/client.d.ts
CHANGED
|
@@ -1,19 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { S as SortedResult } from '../types-Ch8gnVgO.js';
|
|
2
|
+
import { SearchOptions } from '@algolia/client-search';
|
|
3
|
+
import { SearchIndex } from 'algoliasearch/lite';
|
|
4
|
+
|
|
5
|
+
interface FetchOptions {
|
|
6
|
+
/**
|
|
7
|
+
* API route for search endpoint
|
|
8
|
+
*/
|
|
9
|
+
api?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface StaticOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Where to download exported search indexes (URL)
|
|
15
|
+
*/
|
|
16
|
+
from?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface AlgoliaOptions extends SearchOptions {
|
|
20
|
+
index: SearchIndex;
|
|
21
|
+
}
|
|
3
22
|
|
|
4
23
|
interface UseDocsSearch {
|
|
5
24
|
search: string;
|
|
6
25
|
setSearch: (v: string) => void;
|
|
7
|
-
query:
|
|
8
|
-
|
|
9
|
-
|
|
26
|
+
query: {
|
|
27
|
+
isLoading: boolean;
|
|
28
|
+
data?: SortedResult[] | 'empty';
|
|
29
|
+
error?: Error;
|
|
30
|
+
};
|
|
10
31
|
}
|
|
32
|
+
type Client = ({
|
|
33
|
+
type: 'fetch';
|
|
34
|
+
} & FetchOptions) | ({
|
|
35
|
+
type: 'static';
|
|
36
|
+
} & StaticOptions) | ({
|
|
37
|
+
type: 'algolia';
|
|
38
|
+
} & AlgoliaOptions);
|
|
11
39
|
/**
|
|
40
|
+
* @param client - search client
|
|
12
41
|
* @param locale - Filter with locale
|
|
13
42
|
* @param tag - Filter with specific tag
|
|
14
|
-
* @param api - The Search API URL
|
|
15
43
|
* @param delayMs - The debounced delay for performing a search.
|
|
44
|
+
* @param allowEmpty - still perform search even if query is empty
|
|
45
|
+
* @param key - cache key
|
|
16
46
|
*/
|
|
17
|
-
declare function useDocsSearch(locale?: string, tag?: string,
|
|
47
|
+
declare function useDocsSearch(client: Client, locale?: string, tag?: string, delayMs?: number, allowEmpty?: boolean, key?: string): UseDocsSearch;
|
|
18
48
|
|
|
19
49
|
export { useDocsSearch };
|
package/dist/search/client.js
CHANGED
|
@@ -1,32 +1,84 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
useOnChange
|
|
3
|
+
} from "../chunk-I5BWASD6.js";
|
|
4
4
|
import "../chunk-MLKGABMK.js";
|
|
5
5
|
|
|
6
6
|
// src/search/client.ts
|
|
7
|
-
import { useState } from "react";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
import { useMemo, useRef as useRef2, useState as useState2 } from "react";
|
|
8
|
+
|
|
9
|
+
// src/utils/use-debounce.ts
|
|
10
|
+
import { useRef, useState } from "react";
|
|
11
|
+
function useDebounce(value, delayMs = 1e3) {
|
|
12
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
13
|
+
const timer = useRef();
|
|
14
|
+
if (delayMs === 0) return value;
|
|
15
|
+
if (value !== debouncedValue && timer.current?.value !== value) {
|
|
16
|
+
if (timer.current) clearTimeout(timer.current.handler);
|
|
17
|
+
const handler = window.setTimeout(() => {
|
|
18
|
+
setDebouncedValue(value);
|
|
19
|
+
}, delayMs);
|
|
20
|
+
timer.current = { value, handler };
|
|
21
|
+
}
|
|
22
|
+
return debouncedValue;
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
|
|
25
|
+
// src/search/client.ts
|
|
26
|
+
var cache = /* @__PURE__ */ new Map();
|
|
27
|
+
var staticClient;
|
|
28
|
+
function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, key) {
|
|
29
|
+
const [search, setSearch] = useState2("");
|
|
30
|
+
const [results, setResults] = useState2("empty");
|
|
31
|
+
const [error, setError] = useState2();
|
|
32
|
+
const [isLoading, setIsLoading] = useState2(false);
|
|
21
33
|
const debouncedValue = useDebounce(search, delayMs);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
const onStart = useRef2();
|
|
35
|
+
const cacheKey = useMemo(() => {
|
|
36
|
+
return key ?? JSON.stringify([client, debouncedValue, locale, tag]);
|
|
37
|
+
}, [client, debouncedValue, locale, tag, key]);
|
|
38
|
+
useOnChange(cacheKey, () => {
|
|
39
|
+
const cached = cache.get(cacheKey);
|
|
40
|
+
if (onStart.current) {
|
|
41
|
+
onStart.current();
|
|
42
|
+
onStart.current = void 0;
|
|
43
|
+
}
|
|
44
|
+
if (cached) {
|
|
45
|
+
setIsLoading(false);
|
|
46
|
+
setError(void 0);
|
|
47
|
+
setResults(cached);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setIsLoading(true);
|
|
51
|
+
let interrupt = false;
|
|
52
|
+
onStart.current = () => {
|
|
53
|
+
interrupt = true;
|
|
54
|
+
};
|
|
55
|
+
async function run() {
|
|
56
|
+
if (debouncedValue.length === 0 && !allowEmpty) return "empty";
|
|
57
|
+
if (client.type === "fetch") {
|
|
58
|
+
const { fetchDocs } = await import("../fetch-4K7QOPFM.js");
|
|
59
|
+
return fetchDocs(debouncedValue, locale, tag, client);
|
|
60
|
+
}
|
|
61
|
+
if (client.type === "algolia") {
|
|
62
|
+
const { index, type: _, ...rest } = client;
|
|
63
|
+
const { searchDocs } = await import("../algolia-NTWLS6J3.js");
|
|
64
|
+
return searchDocs(index, debouncedValue, tag, rest);
|
|
65
|
+
}
|
|
66
|
+
const { createStaticClient } = await import("../static-5GPJ7RUY.js");
|
|
67
|
+
if (!staticClient) staticClient = createStaticClient(client);
|
|
68
|
+
return staticClient.search(debouncedValue, locale, tag);
|
|
27
69
|
}
|
|
28
|
-
|
|
29
|
-
|
|
70
|
+
void run().then((res) => {
|
|
71
|
+
cache.set(cacheKey, res);
|
|
72
|
+
if (interrupt) return;
|
|
73
|
+
setError(void 0);
|
|
74
|
+
setResults(res);
|
|
75
|
+
}).catch((err) => {
|
|
76
|
+
setError(err);
|
|
77
|
+
}).finally(() => {
|
|
78
|
+
setIsLoading(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return { search, setSearch, query: { isLoading, data: results, error } };
|
|
30
82
|
}
|
|
31
83
|
export {
|
|
32
84
|
useDocsSearch
|
package/dist/search/server.d.ts
CHANGED
|
@@ -1,64 +1,97 @@
|
|
|
1
|
+
import { TypedDocument, Orama, Language, SearchParams, SorterConfig, Tokenizer, DefaultTokenizerConfig, OramaPlugin } from '@orama/orama';
|
|
1
2
|
import { NextRequest } from 'next/server';
|
|
2
3
|
import { S as StructuredData } from '../remark-structure-mP51W1AN.js';
|
|
3
|
-
import { SortedResult } from '
|
|
4
|
+
import { S as SortedResult } from '../types-Ch8gnVgO.js';
|
|
4
5
|
import { I as I18nConfig } from '../config-inq6kP6y.js';
|
|
6
|
+
import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
|
|
5
7
|
import 'mdast';
|
|
6
8
|
import 'unified';
|
|
7
9
|
import 'unist-util-visit';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '../page-tree-r8qjoUla.js';
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
type AdvancedDocument = TypedDocument<Orama<typeof advancedSchema>>;
|
|
14
|
+
declare const advancedSchema: {
|
|
15
|
+
readonly content: "string";
|
|
16
|
+
readonly page_id: "string";
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly keywords: "string";
|
|
19
|
+
readonly tag: "string";
|
|
20
|
+
readonly url: "string";
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type SimpleDocument = TypedDocument<Orama<typeof schema>>;
|
|
24
|
+
declare const schema: {
|
|
25
|
+
readonly url: "string";
|
|
26
|
+
readonly title: "string";
|
|
27
|
+
readonly description: "string";
|
|
28
|
+
readonly content: "string";
|
|
29
|
+
readonly keywords: "string";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type LocaleMap<O> = Record<string, Language | O>;
|
|
33
|
+
type Options$1<O extends SimpleOptions | AdvancedOptions, Idx> = Omit<O, 'language' | 'indexes'> & {
|
|
14
34
|
i18n: I18nConfig;
|
|
15
|
-
|
|
16
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Map locale name from i18n config to Orama compatible `language` or options
|
|
37
|
+
*/
|
|
38
|
+
localeMap?: LocaleMap<Partial<O>>;
|
|
39
|
+
indexes: WithLocale<Idx>[] | Dynamic<WithLocale<Idx>>;
|
|
40
|
+
};
|
|
41
|
+
type I18nSimpleOptions = Options$1<SimpleOptions, Index>;
|
|
42
|
+
type I18nAdvancedOptions = Options$1<AdvancedOptions, AdvancedIndex>;
|
|
17
43
|
type WithLocale<T> = T & {
|
|
18
44
|
locale: string;
|
|
19
45
|
};
|
|
20
|
-
declare function createI18nSearchAPI
|
|
46
|
+
declare function createI18nSearchAPI<T extends 'simple' | 'advanced'>(type: T, options: T extends 'simple' ? I18nSimpleOptions : I18nAdvancedOptions): SearchAPI;
|
|
21
47
|
|
|
22
|
-
type
|
|
23
|
-
|
|
24
|
-
}> = Omit<T, 'indexes' | 'language'> & {
|
|
25
|
-
indexes: ([language: string, indexes: T['indexes']] | {
|
|
26
|
-
language: string;
|
|
27
|
-
indexes: T['indexes'];
|
|
28
|
-
})[];
|
|
48
|
+
type Options = Omit<AdvancedOptions, 'language' | 'indexes'> & {
|
|
49
|
+
localeMap?: LocaleMap<Partial<AdvancedOptions>>;
|
|
29
50
|
};
|
|
30
|
-
declare function
|
|
51
|
+
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, pageToIndex?: (page: InferPageType<S>) => AdvancedIndex, options?: Options): SearchAPI;
|
|
31
52
|
|
|
32
53
|
interface SearchServer {
|
|
33
54
|
search: (query: string, options?: {
|
|
34
55
|
locale?: string;
|
|
35
56
|
tag?: string;
|
|
36
57
|
}) => Promise<SortedResult[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Export the database
|
|
60
|
+
*
|
|
61
|
+
* You can reference the exported database to implement client-side search
|
|
62
|
+
*/
|
|
63
|
+
export: () => Promise<unknown>;
|
|
37
64
|
}
|
|
38
65
|
interface SearchAPI extends SearchServer {
|
|
39
66
|
GET: (request: NextRequest) => Promise<Response>;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
67
|
+
/**
|
|
68
|
+
* `GET` route handler that exports search indexes for static search.
|
|
69
|
+
*/
|
|
70
|
+
staticGET: () => Promise<Response>;
|
|
44
71
|
}
|
|
45
72
|
/**
|
|
46
73
|
* Resolve indexes dynamically
|
|
47
74
|
*/
|
|
48
75
|
type Dynamic<T> = () => T[] | Promise<T[]>;
|
|
49
|
-
interface
|
|
50
|
-
indexes: Index[] | Dynamic<Index>;
|
|
76
|
+
interface SharedOptions {
|
|
51
77
|
language?: string;
|
|
78
|
+
sort?: SorterConfig;
|
|
79
|
+
tokenizer?: Tokenizer | DefaultTokenizerConfig;
|
|
80
|
+
plugins?: OramaPlugin[];
|
|
52
81
|
}
|
|
53
|
-
interface
|
|
82
|
+
interface SimpleOptions extends SharedOptions {
|
|
83
|
+
indexes: Index[] | Dynamic<Index>;
|
|
84
|
+
/**
|
|
85
|
+
* Customise search options on server
|
|
86
|
+
*/
|
|
87
|
+
search?: Partial<SearchParams<Orama<typeof schema>, SimpleDocument>>;
|
|
88
|
+
}
|
|
89
|
+
interface AdvancedOptions extends SharedOptions {
|
|
54
90
|
indexes: AdvancedIndex[] | Dynamic<AdvancedIndex>;
|
|
55
91
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @defaultValue false
|
|
92
|
+
* Customise search options on server
|
|
59
93
|
*/
|
|
60
|
-
|
|
61
|
-
language?: string;
|
|
94
|
+
search?: Partial<SearchParams<Orama<typeof advancedSchema>, AdvancedDocument>>;
|
|
62
95
|
}
|
|
63
96
|
declare function createSearchAPI<T extends 'simple' | 'advanced'>(type: T, options: T extends 'simple' ? SimpleOptions : AdvancedOptions): SearchAPI;
|
|
64
97
|
interface Index {
|
|
@@ -68,7 +101,7 @@ interface Index {
|
|
|
68
101
|
url: string;
|
|
69
102
|
keywords?: string;
|
|
70
103
|
}
|
|
71
|
-
declare function initSimpleSearch(
|
|
104
|
+
declare function initSimpleSearch(options: SimpleOptions): SearchServer;
|
|
72
105
|
interface AdvancedIndex {
|
|
73
106
|
id: string;
|
|
74
107
|
title: string;
|
|
@@ -84,6 +117,6 @@ interface AdvancedIndex {
|
|
|
84
117
|
structuredData: StructuredData;
|
|
85
118
|
url: string;
|
|
86
119
|
}
|
|
87
|
-
declare function initAdvancedSearch(
|
|
120
|
+
declare function initAdvancedSearch(options: AdvancedOptions): SearchServer;
|
|
88
121
|
|
|
89
|
-
export { type AdvancedIndex, type AdvancedOptions, type Dynamic, type Index, type SearchAPI, type SearchServer, type SimpleOptions,
|
|
122
|
+
export { type AdvancedIndex, type AdvancedOptions, type Dynamic, type Index, type SearchAPI, type SearchServer, type SimpleOptions, createFromSource, createI18nSearchAPI, createSearchAPI, initAdvancedSearch, initSimpleSearch };
|