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?
最後更新於
