import type { MarkdownHeading } from '@astrojs/markdown-remark'; import type * as rollup from 'rollup'; import type { DataEntry, RenderedContent } from '../../content/data-store.js'; import type { LiveCollectionError } from '../../content/loaders/errors.js'; import type { AstroComponentFactory } from '../../runtime/server/index.js'; import type { AstroConfig } from './config.js'; export interface AstroInstance { file: string; url: string | undefined; default: AstroComponentFactory; } export interface MarkdownInstance> { frontmatter: T; /** Absolute file path (e.g. `/home/user/projects/.../file.md`) */ file: string; /** Browser URL for files under `/src/pages` (e.g. `/en/guides/markdown-content`) */ url: string | undefined; /** Component to render content in `.astro` files. Usage: `` */ Content: AstroComponentFactory; /** raw Markdown file content, excluding layout HTML and YAML frontmatter */ rawContent(): string; /** Markdown file compiled to HTML, excluding layout HTML */ compiledContent(): Promise; /** List of headings (h1 -> h6) with associated metadata */ getHeadings(): MarkdownHeading[]; default: AstroComponentFactory; } export interface MDXInstance> extends Omit, 'rawContent' | 'compiledContent'> { components: Record | undefined; } /** * Props accepted by the MDX `Content` component when using `await render()`. * Allows passing custom components to override default MDX element rendering. * * @example * ```astro * --- * import { getEntry, render } from 'astro:content'; * import MyCustomH1 from '../components/CustomHeading.astro'; * import MyImage from '../images/MyImage.jpg'; * const entry = await getEntry('blog', 'post'); * const { Content } = await render(entry); * --- * * ``` */ export interface MDXContentProps { /** Custom components to use for MDX elements (e.g., h1, h2, img, a, etc.) */ components?: Record; /** Any additional props to pass to the MDX content */ [key: string]: any; } /** * The MDX `Content` component returned from `await render()`. * Extends `AstroComponentFactory` with typed props for better developer experience. */ export type MDXContent = AstroComponentFactory & ((props?: MDXContentProps) => any); export interface MarkdownLayoutProps> { frontmatter: { file: MarkdownInstance['file']; url: MarkdownInstance['url']; } & T; file: MarkdownInstance['file']; url: MarkdownInstance['url']; headings: MarkdownHeading[]; rawContent: MarkdownInstance['rawContent']; compiledContent: MarkdownInstance['compiledContent']; } export interface MDXLayoutProps> extends Omit, 'rawContent' | 'compiledContent'> { components: MDXInstance['components']; } export type ContentEntryModule = { id: string; collection: string; slug: string; body: string; data: Record; _internal: { rawData: string; filePath: string; }; }; export type DataEntryModule = { id: string; collection: string; data: Record; _internal: { rawData: string; filePath: string; }; }; export type ContentEntryRenderFunction = (entry: DataEntry) => Promise; export interface ContentEntryType { extensions: string[]; getEntryInfo(params: { fileUrl: URL; contents: string; }): GetContentEntryInfoReturnType | Promise; getRenderModule?(this: rollup.PluginContext, params: { contents: string; fileUrl: URL; viteId: string; }): rollup.LoadResult | Promise; contentModuleTypes?: string; getRenderFunction?(config: AstroConfig): Promise; /** * Handle asset propagation for rendered content to avoid bleed. * Ex. MDX content can import styles and scripts, so `handlePropagation` should be true. * @default true */ handlePropagation?: boolean; } export interface RefreshContentOptions { loaders?: Array; context?: Record; } type GetContentEntryInfoReturnType = { data: Record; /** * Used for error hints to point to correct line and location * Should be the untouched data as read from the file, * including newlines */ rawData: string; body: string; slug: string; }; export interface DataEntryType { extensions: string[]; getEntryInfo(params: { fileUrl: URL; contents: string; }): GetDataEntryInfoReturnType | Promise; } export type GetDataEntryInfoReturnType = { data: Record; rawData?: string; }; export interface CacheHint { /** Cache tags */ tags?: Array; /** Last modified time of the content */ lastModified?: Date; } export interface LiveDataEntry = Record> { /** The ID of the entry. Unique per collection. */ id: string; /** The parsed entry data */ data: TData; /** Optional rendered content */ rendered?: { html: string; }; /** A hint for how to cache this entry */ cacheHint?: CacheHint; } export interface LiveDataCollection = Record> { entries: Array>; /** A hint for how to cache this collection. Individual entries can also have cache hints */ cacheHint?: CacheHint; } export interface LiveDataCollectionResult = Record, TError extends Error = Error> { entries?: Array>; error?: TError | LiveCollectionError; cacheHint?: CacheHint; } export interface LiveDataEntryResult = Record, TError extends Error = Error> { entry?: LiveDataEntry; error?: TError | LiveCollectionError; cacheHint?: CacheHint; } export {};