Skip to content

Commit 12afabf

Browse files
committed
enable search
1 parent 16f1d20 commit 12afabf

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

app/api/search/route.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { source } from '@/lib/source';
2+
import { createFromSource } from 'fumadocs-core/search/server';
3+
4+
// Required for static export
5+
export const revalidate = false;
6+
7+
const server = createFromSource(source, {
8+
// https://docs.orama.com/docs/orama-js/supported-languages
9+
language: 'english',
10+
});
11+
12+
// For static export: generate search indexes at build time
13+
export const GET = server.staticGET;
14+

app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RootProvider } from 'fumadocs-ui/provider/next';
1+
import { Provider } from './provider';
22
import './global.css';
33
import { Inter } from 'next/font/google';
44

@@ -10,7 +10,7 @@ export default function Layout({ children }: LayoutProps<'/'>) {
1010
return (
1111
<html lang="en" className={inter.className} suppressHydrationWarning>
1212
<body className="flex flex-col min-h-screen bg-white dark:bg-slate-950 text-slate-900 dark:text-slate-100">
13-
<RootProvider>{children}</RootProvider>
13+
<Provider>{children}</Provider>
1414
</body>
1515
</html>
1616
);

app/provider.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use client';
2+
3+
import { RootProvider } from 'fumadocs-ui/provider/next';
4+
import SearchDialog from '@/components/search';
5+
import type { ReactNode } from 'react';
6+
7+
export function Provider({ children }: { children: ReactNode }) {
8+
return (
9+
<RootProvider
10+
search={{
11+
SearchDialog,
12+
}}
13+
>
14+
{children}
15+
</RootProvider>
16+
);
17+
}
18+

components/search.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use client';
2+
3+
import { useDocsSearch } from 'fumadocs-core/search/client';
4+
import {
5+
SearchDialog,
6+
SearchDialogClose,
7+
SearchDialogContent,
8+
SearchDialogHeader,
9+
SearchDialogIcon,
10+
SearchDialogInput,
11+
SearchDialogList,
12+
SearchDialogOverlay,
13+
type SharedProps,
14+
} from 'fumadocs-ui/components/dialog/search';
15+
import { create } from '@orama/orama';
16+
17+
function initOrama() {
18+
return create({
19+
schema: { _: 'string' },
20+
// https://docs.orama.com/docs/orama-js/supported-languages
21+
language: 'english',
22+
});
23+
}
24+
25+
export default function DefaultSearchDialog(props: SharedProps) {
26+
const { search, setSearch, query } = useDocsSearch({
27+
type: 'static',
28+
initOrama,
29+
});
30+
31+
return (
32+
<SearchDialog
33+
search={search}
34+
onSearchChange={setSearch}
35+
isLoading={query.isLoading}
36+
{...props}
37+
>
38+
<SearchDialogOverlay />
39+
<SearchDialogContent>
40+
<SearchDialogHeader>
41+
<SearchDialogIcon />
42+
<SearchDialogInput />
43+
<SearchDialogClose />
44+
</SearchDialogHeader>
45+
<SearchDialogList items={query.data !== 'empty' ? query.data : null} />
46+
</SearchDialogContent>
47+
</SearchDialog>
48+
);
49+
}
50+

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"postinstall": "fumadocs-mdx"
1010
},
1111
"dependencies": {
12+
"@orama/orama": "^3.1.16",
1213
"fumadocs-core": "16.0.11",
1314
"fumadocs-mdx": "13.0.8",
1415
"fumadocs-ui": "16.0.11",
@@ -27,4 +28,4 @@
2728
"tailwindcss": "^4.1.16",
2829
"typescript": "^5.9.3"
2930
}
30-
}
31+
}

0 commit comments

Comments
 (0)