Orama Cloud
Fumadocs UI で Orama Cloud を使用する方法。
セットアップ
Fumadocs CLI を使うと、セットアップを自動で行えます。検索ダイアログ、static.json ルート、およびビルドのたびに検索インデックスを同期するスクリプトが作成されます。
npx @fumadocs/cli feature search --provider orama-cloud手動で設定する場合は、次の手順に従います。
-
Orama Cloud を統合します。
-
検索ダイアログを作成し、
endpointとapi_keyを使用する値に置き換えます。components/search.tsx 'use client'; import { SearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogOverlay, type SharedProps, } from 'fumadocs-ui/components/dialog/search'; import { useOramaCloudSearch } from 'fumadocs-core/search/client'; import { OramaCloud } from '@orama/core'; import { useI18n } from 'fumadocs-ui/contexts/i18n'; const orama = new OramaCloud({ projectId: '', apiKey: '', }); export default function CustomSearchDialog(props: SharedProps) { const { locale } = useI18n(); // (optional) for i18n const search = useOramaCloudSearch({ client: orama, locale, }); return ( <SearchDialog {...search} {...props}> <SearchDialogOverlay /> <SearchDialogContent> <SearchDialogHeader> <SearchDialogIcon /> <SearchDialogInput /> <SearchDialogClose /> </SearchDialogHeader> <SearchDialogList /> <SearchDialogFooter> <a href="https://orama.com" rel="noreferrer noopener" className="ms-auto text-xs text-fd-muted-foreground" > Search powered by Orama </a> </SearchDialogFooter> </SearchDialogContent> </SearchDialog> ); }
検索ダイアログを置き換える
ルートレイアウトで、独自の検索ダイアログを <RootProvider /> に渡します。
import { Links, Meta, Scripts, ScrollRestoration } from 'react-router';
import { RootProvider } from 'fumadocs-ui/provider/react-router';
import SearchDialog from '@/components/search';
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body className="flex flex-col min-h-screen">
<RootProvider search={{ SearchDialog }}>{children}</RootProvider>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}How is this guide?
最終更新日
