fumadocs-core 15.6.11 → 15.7.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/dist/breadcrumb.d.ts +1 -1
- package/dist/chunk-HUTQC33E.js +8 -0
- package/dist/chunk-KLUGJRZC.js +72 -0
- package/dist/{chunk-3NX26V7I.js → chunk-NJLFLPV4.js} +0 -2
- package/dist/{page-tree-bSt6K__E.d.ts → definitions-Q95-psoo.d.ts} +16 -12
- package/dist/highlight/client.d.ts +6 -1
- package/dist/highlight/client.js +14 -74
- package/dist/highlight/index.js +1 -1
- package/dist/i18n/index.d.ts +5 -14
- package/dist/i18n/index.js +4 -70
- package/dist/i18n/index.server.d.ts +3 -0
- package/dist/i18n/index.server.js +11 -0
- package/dist/i18n/middleware.d.ts +12 -0
- package/dist/i18n/middleware.js +7 -0
- package/dist/mdx-plugins/index.js +1 -1
- package/dist/search/server.d.ts +15 -14
- package/dist/search/server.js +47 -22
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +23 -22
- package/dist/source/index.d.ts +80 -27
- package/dist/source/index.js +271 -185
- package/dist/utils/use-effect-event.js +1 -1
- package/package.json +17 -12
package/dist/breadcrumb.d.ts
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/i18n/middleware.ts
|
|
2
|
+
import { match as matchLocale } from "@formatjs/intl-localematcher";
|
|
3
|
+
import Negotiator from "negotiator";
|
|
4
|
+
import { NextResponse } from "next/server";
|
|
5
|
+
var COOKIE = "FD_LOCALE";
|
|
6
|
+
function getLocale(request, locales, defaultLanguage) {
|
|
7
|
+
const negotiatorHeaders = {};
|
|
8
|
+
request.headers.forEach((value, key) => {
|
|
9
|
+
negotiatorHeaders[key] = value;
|
|
10
|
+
});
|
|
11
|
+
const languages = new Negotiator({ headers: negotiatorHeaders }).languages(
|
|
12
|
+
locales
|
|
13
|
+
);
|
|
14
|
+
return matchLocale(languages, locales, defaultLanguage);
|
|
15
|
+
}
|
|
16
|
+
var defaultFormat = (locale, path) => {
|
|
17
|
+
return `/${locale}/${path}`;
|
|
18
|
+
};
|
|
19
|
+
function createI18nMiddleware({
|
|
20
|
+
languages,
|
|
21
|
+
defaultLanguage,
|
|
22
|
+
format = defaultFormat,
|
|
23
|
+
hideLocale = "never"
|
|
24
|
+
}) {
|
|
25
|
+
function getUrl(request, pathname, locale) {
|
|
26
|
+
if (!locale) {
|
|
27
|
+
return new URL(
|
|
28
|
+
pathname.startsWith("/") ? pathname : `/${pathname}`,
|
|
29
|
+
request.url
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return new URL(
|
|
33
|
+
format(locale, pathname.startsWith("/") ? pathname.slice(1) : pathname),
|
|
34
|
+
request.url
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return (request) => {
|
|
38
|
+
const inputPath = `${request.nextUrl.pathname}${request.nextUrl.search}`;
|
|
39
|
+
const pathLocale = languages.find(
|
|
40
|
+
(locale) => inputPath.startsWith(`/${locale}/`) || inputPath === `/${locale}`
|
|
41
|
+
);
|
|
42
|
+
if (!pathLocale) {
|
|
43
|
+
if (hideLocale === "default-locale") {
|
|
44
|
+
return NextResponse.rewrite(
|
|
45
|
+
getUrl(request, inputPath, defaultLanguage)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const preferred = getLocale(request, languages, defaultLanguage);
|
|
49
|
+
if (hideLocale === "always") {
|
|
50
|
+
const locale = request.cookies.get(COOKIE)?.value ?? preferred;
|
|
51
|
+
return NextResponse.rewrite(getUrl(request, inputPath, locale));
|
|
52
|
+
}
|
|
53
|
+
return NextResponse.redirect(getUrl(request, inputPath, preferred));
|
|
54
|
+
}
|
|
55
|
+
if (hideLocale === "always") {
|
|
56
|
+
const path = inputPath.slice(`/${pathLocale}`.length);
|
|
57
|
+
const res = NextResponse.redirect(getUrl(request, path));
|
|
58
|
+
res.cookies.set(COOKIE, pathLocale);
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
if (hideLocale === "default-locale" && pathLocale === defaultLanguage) {
|
|
62
|
+
return NextResponse.redirect(
|
|
63
|
+
getUrl(request, inputPath.slice(`/${pathLocale}`.length))
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return NextResponse.next();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
createI18nMiddleware
|
|
72
|
+
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { ReactNode
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
interface Root {
|
|
4
4
|
$id?: string;
|
|
5
5
|
name: ReactNode;
|
|
6
6
|
children: Node[];
|
|
7
|
+
/**
|
|
8
|
+
* Another page tree that won't be displayed unless being opened.
|
|
9
|
+
*/
|
|
10
|
+
fallback?: Root;
|
|
7
11
|
}
|
|
8
12
|
type Node = Item | Separator | Folder;
|
|
9
13
|
interface Item {
|
|
@@ -19,13 +23,13 @@ interface Item {
|
|
|
19
23
|
url: string;
|
|
20
24
|
external?: boolean;
|
|
21
25
|
description?: ReactNode;
|
|
22
|
-
icon?:
|
|
26
|
+
icon?: ReactNode;
|
|
23
27
|
}
|
|
24
28
|
interface Separator {
|
|
25
29
|
$id?: string;
|
|
26
30
|
type: 'separator';
|
|
27
31
|
name?: ReactNode;
|
|
28
|
-
icon?:
|
|
32
|
+
icon?: ReactNode;
|
|
29
33
|
}
|
|
30
34
|
interface Folder {
|
|
31
35
|
$id?: string;
|
|
@@ -41,17 +45,17 @@ interface Folder {
|
|
|
41
45
|
root?: boolean;
|
|
42
46
|
defaultOpen?: boolean;
|
|
43
47
|
index?: Item;
|
|
44
|
-
icon?:
|
|
48
|
+
icon?: ReactNode;
|
|
45
49
|
children: Node[];
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
type
|
|
49
|
-
type
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
type
|
|
53
|
-
declare namespace
|
|
54
|
-
export type {
|
|
52
|
+
type definitions_Folder = Folder;
|
|
53
|
+
type definitions_Item = Item;
|
|
54
|
+
type definitions_Node = Node;
|
|
55
|
+
type definitions_Root = Root;
|
|
56
|
+
type definitions_Separator = Separator;
|
|
57
|
+
declare namespace definitions {
|
|
58
|
+
export type { definitions_Folder as Folder, definitions_Item as Item, definitions_Node as Node, definitions_Root as Root, definitions_Separator as Separator };
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
export { type Folder as F, type Item as I, type Node as N, type Root as R, type Separator as S,
|
|
61
|
+
export { type Folder as F, type Item as I, type Node as N, type Root as R, type Separator as S, definitions as d };
|
|
@@ -4,10 +4,15 @@ import 'shiki';
|
|
|
4
4
|
import 'shiki/themes';
|
|
5
5
|
import 'hast-util-to-jsx-runtime';
|
|
6
6
|
|
|
7
|
-
declare function useShiki(code: string,
|
|
7
|
+
declare function useShiki(code: string, options: HighlightOptions & {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated no longer pre-rendered using scripts.
|
|
10
|
+
*/
|
|
8
11
|
withPrerenderScript?: boolean;
|
|
9
12
|
/**
|
|
10
13
|
* Displayed before highlighter is loaded.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated use React `Suspense` fallback instead.
|
|
11
16
|
*/
|
|
12
17
|
loading?: ReactNode;
|
|
13
18
|
}, deps?: DependencyList): ReactNode;
|
package/dist/highlight/client.js
CHANGED
|
@@ -1,88 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
_highlight,
|
|
4
|
-
_renderHighlight,
|
|
5
3
|
highlight
|
|
6
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-NJLFLPV4.js";
|
|
7
5
|
import "../chunk-JSBRDJBE.js";
|
|
8
6
|
|
|
9
7
|
// src/highlight/client.tsx
|
|
10
8
|
import {
|
|
11
9
|
use,
|
|
12
|
-
useEffect,
|
|
13
10
|
useId,
|
|
14
|
-
useMemo
|
|
15
|
-
useRef,
|
|
16
|
-
useState
|
|
11
|
+
useMemo
|
|
17
12
|
} from "react";
|
|
18
|
-
|
|
19
|
-
function useShiki(code, {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
var promises = {};
|
|
14
|
+
function useShiki(code, options, deps) {
|
|
15
|
+
const id = useId();
|
|
16
|
+
const key = useMemo(() => {
|
|
17
|
+
const state = deps ? JSON.stringify(deps) : `${options.lang}:${code}`;
|
|
18
|
+
return `${id}:${state}`;
|
|
19
|
+
}, [code, deps, id, options.lang]);
|
|
20
|
+
return use(
|
|
21
|
+
promises[key] ??= highlight(code, {
|
|
22
|
+
...options,
|
|
23
|
+
engine: options.engine ?? "js"
|
|
24
|
+
})
|
|
28
25
|
);
|
|
29
|
-
const shikiOptions = {
|
|
30
|
-
...options,
|
|
31
|
-
engine: options.engine ?? "js"
|
|
32
|
-
};
|
|
33
|
-
const currentTask = useRef({
|
|
34
|
-
key,
|
|
35
|
-
aborted: false
|
|
36
|
-
});
|
|
37
|
-
const [rendered, setRendered] = useState(() => {
|
|
38
|
-
const element = withPrerenderScript && typeof document !== "undefined" ? document.querySelector(`[data-markup-id="${markupId}"]`) : null;
|
|
39
|
-
const attr = element?.getAttribute("data-markup");
|
|
40
|
-
if (attr) {
|
|
41
|
-
const hast = JSON.parse(attr);
|
|
42
|
-
return renderHighlightWithMarkup(markupId, hast, shikiOptions, attr);
|
|
43
|
-
}
|
|
44
|
-
currentTask.current = void 0;
|
|
45
|
-
return loading;
|
|
46
|
-
});
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (currentTask.current?.key === key) return;
|
|
49
|
-
if (currentTask.current) {
|
|
50
|
-
currentTask.current.aborted = true;
|
|
51
|
-
}
|
|
52
|
-
const task = {
|
|
53
|
-
key,
|
|
54
|
-
aborted: false
|
|
55
|
-
};
|
|
56
|
-
currentTask.current = task;
|
|
57
|
-
void highlight(code, shikiOptions).then((result) => {
|
|
58
|
-
if (!task.aborted) setRendered(result);
|
|
59
|
-
});
|
|
60
|
-
}, [key]);
|
|
61
|
-
if (typeof window === "undefined") {
|
|
62
|
-
return use(
|
|
63
|
-
_highlight(code, shikiOptions).then(
|
|
64
|
-
(tree) => renderHighlightWithMarkup(markupId, tree, shikiOptions)
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
return rendered;
|
|
69
|
-
}
|
|
70
|
-
function renderHighlightWithMarkup(id, tree, shikiOptions, rawAttr) {
|
|
71
|
-
const Pre = shikiOptions.components?.pre ?? "pre";
|
|
72
|
-
return _renderHighlight(tree, {
|
|
73
|
-
...shikiOptions,
|
|
74
|
-
components: {
|
|
75
|
-
...shikiOptions.components,
|
|
76
|
-
pre: (props) => /* @__PURE__ */ jsx(
|
|
77
|
-
Pre,
|
|
78
|
-
{
|
|
79
|
-
...props,
|
|
80
|
-
"data-markup-id": id,
|
|
81
|
-
"data-markup": rawAttr ?? JSON.stringify(tree)
|
|
82
|
-
}
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
26
|
}
|
|
87
27
|
export {
|
|
88
28
|
useShiki
|
package/dist/highlight/index.js
CHANGED
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
interface MiddlewareOptions extends I18nConfig {
|
|
4
|
-
/**
|
|
5
|
-
* A function that adds the locale prefix to path name
|
|
6
|
-
*/
|
|
7
|
-
format?: (locale: string, path: string) => string;
|
|
8
|
-
}
|
|
9
|
-
declare function createI18nMiddleware({ languages, defaultLanguage, format, hideLocale, }: MiddlewareOptions): NextMiddleware;
|
|
10
|
-
|
|
11
|
-
interface I18nConfig {
|
|
1
|
+
interface I18nConfig<Languages extends string = string> {
|
|
12
2
|
/**
|
|
13
3
|
* Supported locale codes.
|
|
14
4
|
*
|
|
15
5
|
* A page tree will be built for each language.
|
|
16
6
|
*/
|
|
17
|
-
languages:
|
|
7
|
+
languages: Languages[];
|
|
18
8
|
/**
|
|
19
9
|
* Default locale if not specified
|
|
20
10
|
*/
|
|
21
|
-
defaultLanguage:
|
|
11
|
+
defaultLanguage: Languages;
|
|
22
12
|
/**
|
|
23
13
|
* Don't show the locale prefix on URL.
|
|
24
14
|
*
|
|
@@ -38,5 +28,6 @@ interface I18nConfig {
|
|
|
38
28
|
*/
|
|
39
29
|
parser?: 'dot' | 'dir';
|
|
40
30
|
}
|
|
31
|
+
declare function defineI18n<Languages extends string>(config: I18nConfig<Languages>): I18nConfig<Languages>;
|
|
41
32
|
|
|
42
|
-
export { type I18nConfig,
|
|
33
|
+
export { type I18nConfig, defineI18n };
|
package/dist/i18n/index.js
CHANGED
|
@@ -1,73 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineI18n
|
|
3
|
+
} from "../chunk-HUTQC33E.js";
|
|
1
4
|
import "../chunk-JSBRDJBE.js";
|
|
2
|
-
|
|
3
|
-
// src/i18n/middleware.ts
|
|
4
|
-
import { match as matchLocale } from "@formatjs/intl-localematcher";
|
|
5
|
-
import Negotiator from "negotiator";
|
|
6
|
-
import { NextResponse } from "next/server";
|
|
7
|
-
var COOKIE = "FD_LOCALE";
|
|
8
|
-
function getLocale(request, locales, defaultLanguage) {
|
|
9
|
-
const negotiatorHeaders = {};
|
|
10
|
-
request.headers.forEach((value, key) => {
|
|
11
|
-
negotiatorHeaders[key] = value;
|
|
12
|
-
});
|
|
13
|
-
const languages = new Negotiator({ headers: negotiatorHeaders }).languages(
|
|
14
|
-
locales
|
|
15
|
-
);
|
|
16
|
-
return matchLocale(languages, locales, defaultLanguage);
|
|
17
|
-
}
|
|
18
|
-
var defaultFormat = (locale, path) => {
|
|
19
|
-
return `/${locale}/${path}`;
|
|
20
|
-
};
|
|
21
|
-
function createI18nMiddleware({
|
|
22
|
-
languages,
|
|
23
|
-
defaultLanguage,
|
|
24
|
-
format = defaultFormat,
|
|
25
|
-
hideLocale = "never"
|
|
26
|
-
}) {
|
|
27
|
-
function getUrl(request, pathname, locale) {
|
|
28
|
-
if (!locale) {
|
|
29
|
-
return new URL(
|
|
30
|
-
pathname.startsWith("/") ? pathname : `/${pathname}`,
|
|
31
|
-
request.url
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return new URL(
|
|
35
|
-
format(locale, pathname.startsWith("/") ? pathname.slice(1) : pathname),
|
|
36
|
-
request.url
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return (request) => {
|
|
40
|
-
const inputPath = `${request.nextUrl.pathname}${request.nextUrl.search}`;
|
|
41
|
-
const pathLocale = languages.find(
|
|
42
|
-
(locale) => inputPath.startsWith(`/${locale}/`) || inputPath === `/${locale}`
|
|
43
|
-
);
|
|
44
|
-
if (!pathLocale) {
|
|
45
|
-
if (hideLocale === "default-locale") {
|
|
46
|
-
return NextResponse.rewrite(
|
|
47
|
-
getUrl(request, inputPath, defaultLanguage)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
const preferred = getLocale(request, languages, defaultLanguage);
|
|
51
|
-
if (hideLocale === "always") {
|
|
52
|
-
const locale = request.cookies.get(COOKIE)?.value ?? preferred;
|
|
53
|
-
return NextResponse.rewrite(getUrl(request, inputPath, locale));
|
|
54
|
-
}
|
|
55
|
-
return NextResponse.redirect(getUrl(request, inputPath, preferred));
|
|
56
|
-
}
|
|
57
|
-
if (hideLocale === "always") {
|
|
58
|
-
const path = inputPath.slice(`/${pathLocale}`.length);
|
|
59
|
-
const res = NextResponse.redirect(getUrl(request, path));
|
|
60
|
-
res.cookies.set(COOKIE, pathLocale);
|
|
61
|
-
return res;
|
|
62
|
-
}
|
|
63
|
-
if (hideLocale === "default-locale" && pathLocale === defaultLanguage) {
|
|
64
|
-
return NextResponse.redirect(
|
|
65
|
-
getUrl(request, inputPath.slice(`/${pathLocale}`.length))
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
return NextResponse.next();
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
5
|
export {
|
|
72
|
-
|
|
6
|
+
defineI18n
|
|
73
7
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { I18nConfig } from './index.js';
|
|
2
|
+
import { NextMiddleware } from 'next/dist/server/web/types';
|
|
3
|
+
|
|
4
|
+
interface MiddlewareOptions extends I18nConfig {
|
|
5
|
+
/**
|
|
6
|
+
* A function that adds the locale prefix to path name
|
|
7
|
+
*/
|
|
8
|
+
format?: (locale: string, path: string) => string;
|
|
9
|
+
}
|
|
10
|
+
declare function createI18nMiddleware({ languages, defaultLanguage, format, hideLocale, }: MiddlewareOptions): NextMiddleware;
|
|
11
|
+
|
|
12
|
+
export { createI18nMiddleware };
|
package/dist/search/server.d.ts
CHANGED
|
@@ -7,9 +7,8 @@ import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
|
|
|
7
7
|
import 'mdast';
|
|
8
8
|
import 'unified';
|
|
9
9
|
import 'mdast-util-mdx-jsx';
|
|
10
|
-
import 'next/dist/server/web/types';
|
|
11
10
|
import 'react';
|
|
12
|
-
import '../
|
|
11
|
+
import '../definitions-Q95-psoo.js';
|
|
13
12
|
|
|
14
13
|
type AdvancedDocument = TypedDocument<Orama<typeof advancedSchema>>;
|
|
15
14
|
declare const advancedSchema: {
|
|
@@ -28,13 +27,25 @@ declare const simpleSchema: {
|
|
|
28
27
|
readonly keywords: "string";
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
type
|
|
30
|
+
type Awaitable<T> = T | Promise<T>;
|
|
31
|
+
interface Options<S extends LoaderOutput<LoaderConfig>> extends Omit<AdvancedOptions, 'indexes'> {
|
|
32
|
+
localeMap?: {
|
|
33
|
+
[K in S extends LoaderOutput<infer C> ? C['i18n'] extends I18nConfig<infer Languages> ? Languages : string : string]?: Partial<AdvancedOptions> | Language;
|
|
34
|
+
};
|
|
35
|
+
buildIndex?: (page: InferPageType<S>) => Awaitable<AdvancedIndex>;
|
|
36
|
+
}
|
|
37
|
+
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, options?: Options<S>): SearchAPI;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `createFromSource(source, options)` instead.
|
|
40
|
+
*/
|
|
41
|
+
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, pageToIndexFn?: (page: InferPageType<S>) => Awaitable<AdvancedIndex>, options?: Omit<Options<S>, 'buildIndex'>): SearchAPI;
|
|
42
|
+
|
|
32
43
|
type I18nOptions<O extends SimpleOptions | AdvancedOptions, Idx> = Omit<O, 'language' | 'indexes'> & {
|
|
33
44
|
i18n: I18nConfig;
|
|
34
45
|
/**
|
|
35
46
|
* Map locale name from i18n config to Orama compatible `language` or options
|
|
36
47
|
*/
|
|
37
|
-
localeMap?:
|
|
48
|
+
localeMap?: Record<string, Language | Partial<O> | undefined>;
|
|
38
49
|
indexes: WithLocale<Idx>[] | Dynamic<WithLocale<Idx>>;
|
|
39
50
|
};
|
|
40
51
|
type I18nSimpleOptions = I18nOptions<SimpleOptions, Index>;
|
|
@@ -44,16 +55,6 @@ type WithLocale<T> = T & {
|
|
|
44
55
|
};
|
|
45
56
|
declare function createI18nSearchAPI<T extends 'simple' | 'advanced'>(type: T, options: T extends 'simple' ? I18nSimpleOptions : I18nAdvancedOptions): SearchAPI;
|
|
46
57
|
|
|
47
|
-
interface Options<Page = unknown> extends Omit<AdvancedOptions, 'indexes'> {
|
|
48
|
-
localeMap?: LocaleMap<Partial<AdvancedOptions>>;
|
|
49
|
-
buildIndex?: (page: Page) => AdvancedIndex;
|
|
50
|
-
}
|
|
51
|
-
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, options?: Options<InferPageType<S>>): SearchAPI;
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated Use `createFromSource(source, options)` instead.
|
|
54
|
-
*/
|
|
55
|
-
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, pageToIndexFn?: (page: InferPageType<S>) => AdvancedIndex, options?: Omit<Options, 'buildIndex'>): SearchAPI;
|
|
56
|
-
|
|
57
58
|
type SearchType = 'simple' | 'advanced';
|
|
58
59
|
type ExportedData = (RawData & {
|
|
59
60
|
type: SearchType;
|
package/dist/search/server.js
CHANGED
|
@@ -148,13 +148,17 @@ async function createDBSimple({
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
// src/search/orama/create-from-source.ts
|
|
151
|
-
function pageToIndex(page) {
|
|
152
|
-
|
|
151
|
+
async function pageToIndex(page) {
|
|
152
|
+
let structuredData;
|
|
153
|
+
if ("structuredData" in page.data) {
|
|
154
|
+
structuredData = page.data.structuredData;
|
|
155
|
+
} else if ("load" in page.data && typeof page.data.load === "function") {
|
|
156
|
+
structuredData = (await page.data.load()).structuredData;
|
|
157
|
+
}
|
|
158
|
+
if (!structuredData)
|
|
153
159
|
throw new Error(
|
|
154
160
|
"Cannot find structured data from page, please define the page to index function."
|
|
155
161
|
);
|
|
156
|
-
}
|
|
157
|
-
const structuredData = page.data.structuredData;
|
|
158
162
|
return {
|
|
159
163
|
title: page.data.title ?? basename(page.path, extname(page.path)),
|
|
160
164
|
description: "description" in page.data ? page.data.description : void 0,
|
|
@@ -164,32 +168,53 @@ function pageToIndex(page) {
|
|
|
164
168
|
};
|
|
165
169
|
}
|
|
166
170
|
function createFromSource(source, _buildIndexOrOptions = pageToIndex, _options) {
|
|
167
|
-
const options = {
|
|
171
|
+
const { buildIndex = pageToIndex, ...options } = {
|
|
168
172
|
...typeof _buildIndexOrOptions === "function" ? {
|
|
169
173
|
buildIndex: _buildIndexOrOptions
|
|
170
174
|
} : _buildIndexOrOptions,
|
|
171
175
|
..._options
|
|
172
176
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
177
|
+
const i18n = source._i18n;
|
|
178
|
+
let server;
|
|
179
|
+
if (i18n) {
|
|
180
|
+
const indexes = source.getLanguages().flatMap((entry) => {
|
|
181
|
+
return entry.pages.map(async (page) => ({
|
|
182
|
+
...await buildIndex(page),
|
|
183
|
+
locale: entry.language
|
|
184
|
+
}));
|
|
185
|
+
});
|
|
186
|
+
server = Promise.all(indexes).then(
|
|
187
|
+
(loaded) => createI18nSearchAPI("advanced", {
|
|
188
|
+
...options,
|
|
189
|
+
i18n,
|
|
190
|
+
indexes: loaded
|
|
184
191
|
})
|
|
192
|
+
);
|
|
193
|
+
} else {
|
|
194
|
+
const indexes = source.getPages().map(async (page) => {
|
|
195
|
+
return buildIndex(page);
|
|
185
196
|
});
|
|
197
|
+
server = Promise.all(indexes).then(
|
|
198
|
+
(loaded) => createSearchAPI("advanced", {
|
|
199
|
+
...options,
|
|
200
|
+
indexes: loaded
|
|
201
|
+
})
|
|
202
|
+
);
|
|
186
203
|
}
|
|
187
|
-
return
|
|
188
|
-
...
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
204
|
+
return {
|
|
205
|
+
async export(...args) {
|
|
206
|
+
return (await server).export(...args);
|
|
207
|
+
},
|
|
208
|
+
async GET(...args) {
|
|
209
|
+
return (await server).GET(...args);
|
|
210
|
+
},
|
|
211
|
+
async search(...args) {
|
|
212
|
+
return (await server).search(...args);
|
|
213
|
+
},
|
|
214
|
+
async staticGET(...args) {
|
|
215
|
+
return (await server).staticGET(...args);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
193
218
|
}
|
|
194
219
|
|
|
195
220
|
// src/search/orama/_stemmers.ts
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-Cr2URuiP.js';
|
|
2
|
-
import { N as Node, I as Item, R as Root, F as Folder } from '../
|
|
3
|
-
export {
|
|
2
|
+
import { N as Node, I as Item, R as Root, F as Folder } from '../definitions-Q95-psoo.js';
|
|
3
|
+
export { d as PageTree } from '../definitions-Q95-psoo.js';
|
|
4
4
|
import { Metadata } from 'next';
|
|
5
5
|
import { NextRequest } from 'next/server';
|
|
6
6
|
import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
|
|
@@ -9,12 +9,11 @@ import 'react';
|
|
|
9
9
|
import 'unified';
|
|
10
10
|
import 'vfile';
|
|
11
11
|
import '../i18n/index.js';
|
|
12
|
-
import 'next/dist/server/web/types';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Flatten tree to an array of page nodes
|
|
16
15
|
*/
|
|
17
|
-
declare function flattenTree(
|
|
16
|
+
declare function flattenTree(nodes: Node[]): Item[];
|
|
18
17
|
/**
|
|
19
18
|
* Get neighbours of a page, useful for implementing "previous & next" buttons
|
|
20
19
|
*/
|
|
@@ -27,6 +26,8 @@ declare function findNeighbour(tree: Root, url: string, options?: {
|
|
|
27
26
|
declare function getPageTreeRoots(pageTree: Root | Folder): (Root | Folder)[];
|
|
28
27
|
/**
|
|
29
28
|
* Separate the folder nodes of a root into multiple roots
|
|
29
|
+
*
|
|
30
|
+
* @deprecated it's useless
|
|
30
31
|
*/
|
|
31
32
|
declare function separatePageTree(pageTree: Root): Root[];
|
|
32
33
|
/**
|