Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
The loadServerPageIndex utility reads a markdown file and extracts page metadata for use in sitemaps. It parses the markdown content, extracts titles, descriptions, sections, and keywords, and derives additional metadata like URL prefix from the file path.
Note
This function is primarily used internally by
loadServerSitemapto process individual page files. Most users won't need to call it directly.
import { loadServerPageIndex } from '@mui/internal-docs-infra/pipeline/loadServerPageIndex';
// Load metadata from a markdown file
const pageData = await loadServerPageIndex('file:///path/to/docs-infra/components/page.mdx');
// Returns: { title: 'Docs Infra Components', prefix: '/docs-infra/components/', pages: [...] }
The function:
markdownToMetadata to extract page dataSitemapSectionData objectimport { loadServerPageIndex } from '@mui/internal-docs-infra/pipeline/loadServerPageIndex';
const data = await loadServerPageIndex('file:///app/docs-infra/functions/page.mdx');
// Returns:
// {
// title: 'Docs Infra Functions',
// prefix: '/docs-infra/functions/',
// pages: [
// {
// slug: 'load-server-code-meta',
// path: './load-server-code-meta/page.mdx',
// title: 'Load Server Code Meta',
// description: 'Parses demo files to extract variant information...',
// keywords: ['code', 'meta', 'demo'],
// sections: { ... }
// },
// // ... more pages
// ]
// }
When your files are not at the default location:
import { createLoadServerPageIndex } from '@mui/internal-docs-infra/pipeline/loadServerPageIndex';
const loadPageIndex = createLoadServerPageIndex({
rootContext: '/custom/docs/root',
});
const data = await loadPageIndex('file:///custom/docs/root/components/page.mdx');
// prefix will be '/components/' instead of the full path
The loader automatically processes file paths to generate useful metadata.
Converts kebab-case path segments to Title Case:
import { pathSegmentToTitle } from '@mui/internal-docs-infra/pipeline/loadServerPageIndex';
pathSegmentToTitle('docs-infra'); // 'Docs Infra'
pathSegmentToTitle('code-highlighter'); // 'Code Highlighter'
pathSegmentToTitle('abstract-create-demo'); // 'Abstract Create Demo'
The extractPrefixAndTitle function generates URL prefixes from directory structure:
import { extractPrefixAndTitle } from '@mui/internal-docs-infra/pipeline/loadServerPageIndex';
extractPrefixAndTitle('/app/docs-infra/components/page.mdx', '/app');
// { prefix: '/docs-infra/components/', title: 'Docs Infra Components' }
extractPrefixAndTitle('/app/(public)/blog/page.mdx', '/app');
// { prefix: '/blog/', title: 'Blog' } (route groups are removed)
extractPrefixAndTitle('/src/app/page.mdx', '/src/app');
// { prefix: '/', title: '' }
Note
extractPrefixAndTitleexpects absolute file paths (withoutfile://prefix), not file URLs.
The following are automatically removed from paths:
src - Only if at the startapp - Only if at the start (or after src)(public), (content). and empty stringsThe loader automatically optimizes the metadata to reduce bundle size:
descriptionMarkdown - Raw markdown AST for descriptions (can be 50%+ of size)titleMarkdown - Raw markdown AST for section titleschildren: {} - Empty children objects are converted to undefinedBefore optimization:
{
sections: {
features: {
title: 'Features',
titleMarkdown: { type: 'root', children: [...] }, // Removed
children: {} // Converted to undefined
}
},
descriptionMarkdown: { type: 'root', children: [...] } // Removed
}
After optimization:
{
sections: {
features: {
title: 'Features',
children: undefined
}
}
}
loadServerPageIndexDefault loadServerPageIndex function that loads page index data from a markdown file. This function uses process.cwd() as the root context for resolving relative paths.
| Parameter | Type | Description |
|---|---|---|
| filePath | string |
Promise<SitemapSectionData | null>createLoadServerPageIndexCreates a loadServerPageIndex function with custom options.
This factory function creates a LoadServerPageIndex implementation that:
| Parameter | Type | Description |
|---|---|---|
| options | CreateLoadServerPageIndexOptions | undefined | Configuration options for the loader |
((filePath: string) => Promise<SitemapSectionData | null>)LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
extractPrefixAndTitleExtracts prefix and title from an import path e.g., “/path/to/app/docs-infra/components/page.mdx” -> { prefix: “/docs-infra/components/", title: “Docs Infra Components” }
| Parameter | Type | Description |
|---|---|---|
| absolutePath | string | |
| rootContext | string |
| Key | Type | Description |
|---|---|---|
| prefix | string | |
| title | string |
pathSegmentToTitleConverts a path segment to a title e.g., “docs-infra” -> “Docs Infra”, “components” -> “Components”
| Parameter | Type | Description |
|---|---|---|
| segment | string |
stringstripTitleMarkdownRecursively removes titleMarkdown fields from a heading hierarchy
| Parameter | Type | Description |
|---|---|---|
| hierarchy | { [slug: string]: { title: string; titleMarkdown: PhrasingContent[]; children: HeadingHierarchy } } |
Record<string, SitemapSection>Options for creating a loadServerPageIndex function
type CreateLoadServerPageIndexOptions = { rootContext?: string };transformMarkdownMetadata - Remark plugin that extracts metadataloadPrecomputedSitemap - Build-time sitemap processing