跳至內容
Fumadocs

自訂搜尋

適用於其他搜尋方案。

概覽

您可以將任何搜尋引擎整合到 Fumadocs 中。

搜尋索引

Fumadocs MDX 會在執行階段提供您頁面的搜尋索引。

若要將其靜態匯出,請新增一個預先算繪的 static.json 路由,並在每次建置後以指令碼處理其中的紀錄:

import { source } from '@/lib/source';

async function getDocuments() {
  const documents = [];
  for (const page of source.getPages()) {
    documents.push({
      structured: await page.data.structuredData(),
      url: page.url,
      title: page.data.title,
      description: page.data.description,
    });
  }
  return documents;
}

export const revalidate = false;

export async function GET() {
  return Response.json(await getDocuments());
}

structured 欄位包含每個頁面的標題與段落,可用來產生精確的搜尋索引。

How is this guide?

最後更新於