Fumadocs rebuilt on Hamur, the original is fumadocs.dev
コンテンツへスキップ
Fumadocs

Orama Cloud

Orama Cloud との連携

まず、Orama Cloud でアカウントを作成してください。

REST API

REST API 連携では、ドキュメント側からインデックスをアップロードする必要があります。

  1. Orama Cloud のダッシュボードで、REST API データソースを使用する新しいプロジェクトを作成します。

    認証情報は .env.local などに保存します (NEXT_PUBLIC_ は、Vite 系フレームワークでは VITE_、Astro では PUBLIC_ になります) 。

    NEXT_PUBLIC_ORAMA_DATASOURCE_ID="Rest API data source ID"
    NEXT_PUBLIC_ORAMA_PROJECT_ID="project ID"
    NEXT_PUBLIC_ORAMA_API_KEY="public API key"
    
    ORAMA_PRIVATE_API_KEY="private API key"
  2. static.json ルートを事前レンダリングしてビルド時に検索インデックスをエクスポートし、ビルドのたびにスクリプトで Orama Cloud に同期します。

    app/static.json/route.ts
    import { source } from '@/lib/source';
    import { toDocuments } from 'fumadocs-core/search/orama-cloud';
    
    export const revalidate = false;
    
    export async function GET() {
      return Response.json(await toDocuments(source));
    }
    
    scripts/sync-content.ts
    import * as fs from 'node:fs/promises';
    import { type OramaDocument as DocumentRecord, sync } from 'fumadocs-core/search/orama-cloud';
    import { OramaCloud } from '@orama/core';
    
    // Next.js writes it under `route-cache` when built with an adapter, like on Vercel
    const [file] = await Array.fromAsync(fs.glob('.next/server/{app,route-cache/*/*/$}/static.json.body'));
    const records = JSON.parse(await fs.readFile(file, 'utf-8')) as DocumentRecord[];
    
    const orama = new OramaCloud({
      projectId: process.env.NEXT_PUBLIC_ORAMA_PROJECT_ID!,
      apiKey: process.env.ORAMA_PRIVATE_API_KEY!,
    });
    
    await sync(orama, {
      index: process.env.NEXT_PUBLIC_ORAMA_DATASOURCE_ID!,
      documents: records,
    });
    
    console.log(`search updated: ${records.length} records`);
    
    package.json
    {
      "scripts": {
        "build": "next build && node --env-file-if-exists=.env.local scripts/sync-content.ts"
      }
    }

    build スクリプトはビルドのたびに同期を行うため、デプロイ先のプラットフォームにも同じ環境変数を設定してください。

検索クライアント

クライアント側でドキュメントを検索するには、次の方法を検討してください。

  • Fumadocs UI の検索ダイアログを使用する。

  • Fumadocs の組み込みフックを使用して、独自の検索 UI を作成する。

    import { useOramaCloudSearch } from 'fumadocs-core/search/client';
    import { OramaCloud } from '@orama/core';
    
    const orama = new OramaCloud({
      projectId: process.env.NEXT_PUBLIC_ORAMA_PROJECT_ID,
      apiKey: process.env.NEXT_PUBLIC_ORAMA_API_KEY,
    });
    
    const params = {
      // 任意の検索パラメーター
    };
    
    const { search, onSearchChange, isLoading, data } = useOramaCloudSearch({
      client: orama,
      params,
    });
  • Orama の検索クライアントを直接使用する。

Web Crawler

  1. ダッシュボードで Crawler データソースを作成し、「Documentation」プリセットを使って適切に設定してください。
  2. ダッシュボードから認証情報をコピーしてください。

検索クライアント

REST API 連携の場合と同じですが、index は必ず crawler に設定してください。

import { useOramaCloudSearch } from 'fumadocs-core/search/client';
import { OramaCloud } from '@orama/core';

const orama = new OramaCloud({
  projectId: '<project id>',
  apiKey: '<read only api key>',
});

const params = {
  // 検索パラメータ(任意)
};

const { search, onSearchChange, isLoading, data } = useOramaCloudSearch({
  index: 'crawler',
  client: orama,
  params,
});

Fumadocs UI でも同様です。

How is this guide?

最終更新日