Skip to Content
Fumadocs

Custom Search

For other search solutions.

Overview

You can integrate any search engine with Fumadocs.

Search Indexes

Fumadocs MDX exposes the search indexes of your pages at runtime.

To export them statically, add a pre-rendered static.json route, and process its records with a script after each build:

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

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

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

export async function getConfig() {
  return {
    render: 'static' as const,
  } as const;
}

The structured field holds the headings and paragraphs of each page. Use it to generate accurate search indexes.

How is this guide?

Last updated on