glob() loader
The glob() loader populates a collection from many files matching a pattern using the Content Layer API.
Syntax
loader: glob({ pattern, base }) Returns
Loader — A content loader that maps each matched file to a collection entry.
Examples
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const docs = defineCollection({
loader: glob({
pattern: '**/[^_]*.{md,mdx}',
base: './src/data/docs',
}),
schema: z.object({ title: z.string() }),
});
Output
Loads every non-underscore Markdown and MDX file under src/data/docs as a docs entry.
Notes
Imported from astro/loaders. Each file becomes one entry with an id derived from its path (configurable via generateId). The leading underscore convention can exclude drafts. Replaces legacy src/content directory behavior in Astro 5.