Importing Functions
defineCollection
Define a content collection schema in yoursrc/content/config.ts file.
object
required
Collection configuration object.
'content' | 'data'
The type of collection. Use
'content' for Markdown/MDX files with frontmatter, or 'data' for JSON/YAML data files.Default: 'content'ZodSchema
A Zod schema to validate frontmatter or data.
Loader
A loader function for loading collection data. Used with the Content Layer API.
Example
getCollection
Retrieve all entries from a collection, optionally filtered.string
required
The name of the collection to query.
(entry: CollectionEntry) => boolean
Optional filter function to select specific entries.
Promise<CollectionEntry[]>
An array of collection entries with the following properties:
string
Unique identifier for the entry (filename without extension).
string
URL-friendly slug for the entry.
string
The name of the collection this entry belongs to.
object
Parsed and validated frontmatter data matching your schema.
string
Raw Markdown/MDX content (content collections only).
() => Promise<RenderResult>
Function to render the content (content collections only).
Example
getEntry
Retrieve a single entry from a collection.string
required
The name of the collection.
string
required
The entry ID (filename without extension).
Promise<CollectionEntry | undefined>
A single collection entry, or
undefined if not found.Example
getEntries
Retrieve multiple entries by reference.array
required
Array of entry references.
Promise<CollectionEntry[]>
Array of matching collection entries.
Example
reference
Create a reference to entries in another collection.string
required
The name of the collection to reference.
ZodSchema
A Zod schema that validates references to the specified collection.
Example
Rendering Content
Callrender() on a content entry to get renderable content.
AstroComponent
An Astro component containing the rendered content.
MarkdownHeading[]
Array of headings extracted from the content.
Record<string, any>
Frontmatter data modified or injected by remark/rehype plugins.