Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
The loadServerSitemap utility parses sitemap index files to load page metadata at runtime. It reads the sitemap index file, finds createSitemap factory calls, resolves page imports, and builds a complete Sitemap object with schema and data.
Tip
Use this function for runtime loading outside of Next.js builds (e.g., in tests, scripts, or non-Next.js applications).
import { loadServerSitemap } from '@mui/internal-docs-infra/pipeline/loadServerSitemap';
// Load sitemap from a sitemap index file
const sitemap = await loadServerSitemap('file:///app/sitemap/index.ts');
// Returns: { schema: {...}, data: { DocsInfraComponents: {...}, DocsInfraFunctions: {...} } }
The function:
createSitemap() call and extracts page importsSitemap object with schema and dataGiven a sitemap index file:
// app/sitemap/index.ts
import { createSitemap } from '../functions/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,
});
You can load it at runtime:
const sitemap = await loadServerSitemap('file:///path/to/app/sitemap/index.ts');
// Returns:
// {
// schema: {
// slug: 'string',
// path: 'string',
// title: 'string',
// description: 'string',
// sections: 'string[]',
// subsections: 'string[]',
// keywords: 'string[]',
// },
// data: {
// DocsInfraComponents: {
// title: 'Docs Infra Components',
// prefix: '/docs-infra/components/',
// pages: [...]
// },
// DocsInfraFunctions: {
// title: 'Docs Infra Functions',
// prefix: '/docs-infra/functions/',
// pages: [...]
// }
// }
// }
Create a custom loadServerSitemap function using the factory:
import { createLoadServerSitemap } from '@mui/internal-docs-infra/pipeline/loadServerSitemap';
const customLoadSitemap = createLoadServerSitemap({
// Override the root context for resolving relative paths
rootContext: '/custom/root/path',
});
const sitemap = await customLoadSitemap('file:///path/to/sitemap/index.ts');
Using 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:///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]) => {
return section.pages.map((page) => ({
...page,
section: section.title,
prefix: section.prefix,
}));
});
await insertMultiple(searchIndex, pages);
// Search
const results = await search(searchIndex, { term: 'code' });
| Feature | Build-Time (Webpack Loader) | Runtime (loadServerSitemap) |
|---|---|---|
| When processed | During Next.js build | At runtime when called |
| Caching | Webpack dependency cache | Manual caching via Map |
| Environment | Next.js only | Any Node.js environment |
| Use case | Production builds | Tests, scripts, non-Next.js apps |
| Performance | Fastest (precomputed) | Slower (reads files at runtime) |
loadServerSitemapDefault loadServerSitemap function that loads sitemap data from a sitemap index file. This function parses the sitemap index file to find createSitemap calls and resolves the page index paths from the imports.
| Parameter | Type | Description |
|---|---|---|
| url | string |
Promise<Sitemap>createLoadServerSitemapCreates a loadServerSitemap function with custom options.
This factory function creates a LoadServerSitemap implementation that:
| Parameter | Type | Description |
|---|---|---|
| options | CreateLoadServerSitemapOptions | undefined | Configuration options for the loader |
((url: string) => Promise<Sitemap>)LoadServerSitemap function that takes a file URL and returns Promise
createSitemapSchemaCreates the default Orama schema for search indexing. See: https://docs.orama.com/docs/orama-js/usage/create#schema-properties-and-types
Record<string, OramaSchemaType>Options for creating a loadServerSitemap function
type CreateLoadServerSitemapOptions = { rootContext?: string };loadServerPageIndex - Loads individual page metadataloadPrecomputedSitemap - Webpack loader for build-time processing