The createSitemap factory function defines sitemap data for documentation sites. It works with the webpack loader for build-time precomputation in Next.js builds.
Tip
Place your sitemap at
app/sitemap/index.tsfor automatic detection bywithDocsInfra.
import { createSitemap } from '@mui/internal-docs-infra/createSitemap';
import DocsInfraComponents from '../docs-infra/components/page.mdx';
import DocsInfraFunctions from '../docs-infra/functions/page.mdx';
export const sitemap = createSitemap(import.meta.url, {
DocsInfraComponents,
DocsInfraFunctions,
});
During Next.js builds, the loadPrecomputedSitemap webpack loader processes this file and precomputes the sitemap data. Outside Next.js, use loadServerSitemap for runtime loading.
function createSitemap(
sourceUrl: string,
pages: Record<string, React.ComponentType>,
meta?: CreateSitemapMeta,
): Sitemap | undefined;
Creates sitemap data from page components with optional precomputed data.
| Parameter | Type | Description |
|---|---|---|
sourceUrl | string | File URL from import.meta.url |
pages | Record<string, React.ComponentType> | Record of page components indexed by key |
meta | CreateSitemapMeta | Optional configuration and precomputed data |
Sitemap object with schema and precomputed page dataundefined (use loadServerSitemap instead)meta.precompute): Returns the precomputed sitemap directlyundefined for graceful fallbackFor loading sitemap data outside of Next.js builds (e.g., in tests, scripts, or non-Next.js applications), use loadServerSitemap:
import { loadServerSitemap } from '@mui/internal-docs-infra/pipeline/loadServerSitemap';
// Load sitemap at runtime by parsing the sitemap index file
const sitemap = await loadServerSitemap('file:///path/to/app/sitemap/index.ts');
// sitemap.schema contains the Orama schema
// sitemap.data contains all page metadata organized by section
The sitemap index file should be placed at app/sitemap/index.ts:
app/
├── sitemap/
│ └── index.ts ← Sitemap definition
├── docs-infra/
│ ├── components/
│ │ └── page.mdx ← Section index
│ └── functions/
│ └── page.mdx ← Section index
Each imported page component should be a markdown file that serves as a section index (e.g., components/page.mdx lists all components).
interface CreateSitemapMeta {
name?: string;
slug?: string;
displayName?: string;
precompute?: Sitemap; // Injected by webpack loader
skipPrecompute?: boolean; // Disable precomputation
}
interface Sitemap {
schema: {
slug: 'string';
path: 'string';
title: 'string';
description: 'string';
sections: 'string[]';
subsections: 'string[]';
keywords: 'string[]';
};
data: Record<string, SitemapSectionData>;
}
interface SitemapSectionData {
title: string;
prefix: string;
pages: SitemapPage[];
}
interface SitemapPage {
slug: string;
path: string;
title: string;
description?: string;
keywords?: string[];
sections?: Record<string, SitemapSection>;
}
Disable precomputation for development or testing:
export const sitemap = createSitemap(
import.meta.url,
{ DocsInfraComponents, DocsInfraFunctions },
{ skipPrecompute: true },
);
The webpack loader must be configured for the sitemap index file. See withDocsInfra or loadPrecomputedSitemap for configuration details.
The sitemap data is designed for use with Orama search:
import { create, insertMultiple, search } from '@orama/orama';
import { loadServerSitemap } from '@mui/internal-docs-infra/pipeline/loadServerSitemap';
// Load the sitemap at runtime
const sitemap = await loadServerSitemap('file:///path/to/app/sitemap/index.ts');
// Create search index with the schema
const searchIndex = await create({
schema: sitemap.schema,
});
// Flatten and insert pages
const pages = Object.entries(sitemap.data).flatMap(([_key, section]) =>
section.pages.map((page) => ({
...page,
section: section.title,
prefix: section.prefix,
})),
);
await insertMultiple(searchIndex, pages);
// Search
const results = await search(searchIndex, { term: 'button' });
The sitemap's page data (titles, descriptions, sections, keywords) comes from metadata exported by each MDX page. Use the transformMarkdownMetadata remark plugin to automatically extract this metadata:
// Each MDX page exports metadata like:
export const metadata = {
title: 'Button',
description: 'A clickable button component.',
keywords: ['button', 'click', 'action'],
};
The plugin extracts:
See transformMarkdownMetadata for configuration options and automatic index generation.
transformMarkdownMetadata - Extract metadata from MDX pagesloadPrecomputedSitemap - Webpack loader for build-time processingloadServerSitemap - Runtime sitemap loadingloadServerPageIndex - Loads individual page metadatawithDocsInfra - Next.js plugin that configures the loader