Model the content an editor can change
Define editable fields, connect related entries, and choose the right editing experience for each file type.
Give a story its own collection
In src/content.config.ts, export named collections with a local glob() loader. The base is relative to the website folder. Margin keeps its posts in src/content/posts/. A site can also use content/ or another local directory such as src/data/.
This small collection gives each article a required headline and an optional description. Add it alongside any collections your project already uses.
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const posts = defineCollection({
loader: glob({ base: './src/content/posts', pattern: '**/*.md' }),
schema: z.object({
title: z.string().min(1),
description: z.string().optional(),
}),
});
export const collections = { posts };
Create src/content/posts/gallery-notes.md with the following content. Open Posts in Studio. The title and description appear in Details, and the paragraph opens in Story.
---
title: Gallery notes
description: A first look at the new exhibition.
---
The gallery opens its doors on Friday.
Choose a file format
- Markdown (
.md) gives writers visual and source editing for the body, with frontmatter in the details form. - MDX (
.mdx) opens the body in the source editor so imports, JSX and expressions survive. Configure@astrojs/mdxin the website to render the preview. - Markdoc (
.mdoc) supports visual editing of Markdown and supported block tags. Configure@astrojs/markdocand the site’s tag renderers. An optionalstudio.components.jsoncan expose component properties as forms. - JSON and YAML work well for structured records such as artists, photos, and site settings.
Use a local directory inside the website for each editable collection. Remote and custom loaders, file() collections, and TOML are outside Studio’s current support. Keep public/ for assets and give editable records their own content directory.
Connect records by ID
In Domus Picturae, an artwork points to an artist. For an existing collection named artists, import reference from astro:content and declare artist: reference('artists') in the artwork schema. For several artists, use z.array(reference('artists')). Studio presents a picker populated from saved artist entries and stores the selected identifier in the artwork file.
If you change an identifier through Studio, it updates incoming declared references. Plain text mentions still need an editorial check. Studio validates changed records against the installed schema before publishing. After changing the schema locally, save or discard the open edit so Studio can refresh its fields. Astro’s content collection reference