コンテンツへスキップ
Fumadocs

Orama Cloud

Fumadocs UI で Orama Cloud を使用する方法。

セットアップ

Fumadocs CLI を使うと、セットアップを自動で行えます。検索ダイアログ、static.json ルート、およびビルドのたびに検索インデックスを同期するスクリプトが作成されます。

npx @fumadocs/cli feature search --provider orama-cloud

手動で設定する場合は、次の手順に従います。

  1. Orama Cloud を統合します。

  2. 検索ダイアログを作成し、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>
      );
    }
    

検索ダイアログを置き換える

ルートのルート (root route) で、独自の検索ダイアログを <RootProvider /> に渡します。

src/routes/__root.tsx
import { createRootRoute, HeadContent, Outlet, Scripts } from '@tanstack/react-router';
import { RootProvider } from 'fumadocs-ui/provider/tanstack';
import SearchDialog from '@/components/search';

export const Route = createRootRoute({
  component: RootComponent,
});

function RootComponent() {
  return (
    <html suppressHydrationWarning>
      <head>
        <HeadContent />
      </head>
      <body className="flex flex-col min-h-screen">
        <RootProvider search={{ SearchDialog }}>
          <Outlet />
        </RootProvider>
        <Scripts />
      </body>
    </html>
  );
}

How is this guide?

最終更新日