跳至內容
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>
      );
    }
    

替換搜尋對話方塊

您的 provider 元件已會將 src/components/search.tsx 傳入 <RootProvider />,因此只要替換該檔案即可:

src/components/provider.tsx
import { navigate } from 'astro:transitions/client';
import type { ReactNode } from 'react';
import { RootProvider } from 'fumadocs-ui/provider/astro';
import SearchDialog from '@/components/search';

export interface ProviderProps {
  pathname: string;
  params: Record<string, string | undefined>;
  children?: ReactNode;
}

export function Provider({ pathname, params, children }: ProviderProps) {
  return (
    <RootProvider
      pathname={pathname}
      params={params}
      navigate={navigate}
      search={{ SearchDialog }}
    >
      {children}
    </RootProvider>
  );
}

How is this guide?

最後更新於