@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
51 lines • 2.21 kB
text/typescript
import type { HeadingHierarchy } from "../transformMarkdownMetadata/types.mjs";
import type { SitemapSection, SitemapSectionData } from "../../createSitemap/types.mjs";
/**
* Options for creating a loadServerPageIndex function
*/
export interface CreateLoadServerPageIndexOptions {
/**
* The root context directory for resolving relative paths.
* Defaults to process.cwd().
*/
rootContext?: string;
}
/**
* Function type for loading page index data from a markdown file
*/
export type LoadServerPageIndex = (filePath: string) => Promise<SitemapSectionData | null>;
/**
* Converts a path segment to a title
* e.g., "docs-infra" -> "Docs Infra", "components" -> "Components"
*/
export declare function pathSegmentToTitle(segment: string): string;
/**
* Recursively removes titleMarkdown fields from a heading hierarchy
*/
export declare function stripTitleMarkdown(hierarchy: HeadingHierarchy): Record<string, SitemapSection>;
/**
* Extracts 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" }
*/
export declare function extractPrefixAndTitle(absolutePath: string, rootContext: string): {
prefix: string;
title: string;
};
/**
* Default loadServerPageIndex function that loads page index data from a markdown file.
* This function uses process.cwd() as the root context for resolving relative paths.
*/
export declare const loadServerPageIndex: LoadServerPageIndex;
/**
* Creates a loadServerPageIndex function with custom options.
*
* This factory function creates a LoadServerPageIndex implementation that:
* 1. Reads the markdown file from the provided file path
* 2. Parses the markdown to extract metadata using markdownToMetadata
* 3. Enriches the metadata with prefix and title derived from the file path
* 4. Returns a SitemapSectionData object with page data
*
* @param options - Configuration options for the loader
* @returns LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
*/
export declare function createLoadServerPageIndex(options?: CreateLoadServerPageIndexOptions): LoadServerPageIndex;