ワンクリックで
content-collection
Set up and evolve Astro content collections with typed schemas and reliable querying patterns.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Set up and evolve Astro content collections with typed schemas and reliable querying patterns.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Add and configure Astro integrations, adapters, and UI framework tooling.
Plan and execute migrations to Astro or between Astro versions with minimal regressions.
Apply performant, accessible, and maintainable defaults when building or reviewing Astro projects.
Create Astro components, pages, and layouts with accessible markup and minimal client-side JavaScript.
Look up official Astro documentation and answer version-sensitive Astro questions accurately.
| name | content-collection |
| description | Set up and evolve Astro content collections with typed schemas and reliable querying patterns. |
Use this skill when creating or refactoring structured content in Astro, such as blogs, docs, changelogs, case studies, team data, or other schema-driven content.
If astro-best-practices is available, apply it alongside this skill for naming, accessibility, and performance defaults.
Most content sites should use build-time collections in src/content.config.*. Only reach for live collections in src/live.config.* when the data truly needs request-time freshness.
Before coding, decide:
Favor a schema that reflects how the site queries content, not just how frontmatter currently looks.
src/content.config.*Use the current Content Layer API. For build-time collections:
src/content.config.ts (or .js / .mjs)loaderz from astro/zodtype: 'content' or type: 'data'Example:
import { defineCollection, reference } from 'astro:content'
import { glob } from 'astro/loaders'
import { z } from 'astro/zod'
const blog = defineCollection({
loader: glob({ base: './src/content/blog', pattern: '**/*.{md,mdx}' }),
schema: ({ image }) => z.object({
title: z.string(),
description: z.string(),
publishDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
author: reference('authors'),
cover: image().optional(),
tags: z.array(z.string()).default([]),
draft: z.boolean().default(false),
}),
})
const authors = defineCollection({
loader: glob({ base: './src/data/authors', pattern: '**/*.json' }),
schema: z.object({
name: z.string(),
email: z.email().optional(),
avatar: z.url().optional(),
}),
})
export const collections = { blog, authors }
Useful patterns:
glob() for folders of local entriesfile() for a single JSON or other data filez.enum(...) for controlled valuesz.coerce.date() for frontmatter datesreference('collection-name') for relationshipsschema: ({ image }) => ... when image validation mattersFor Astro 6 and newer:
src/content.config.*, not src/content/config.*entry.id as the slug-like identifier in URLs and queriesentry.filePath only when you truly need the source pathgetEntry() instead of legacy getEntryBySlug() or getDataEntryById()Prefer a stable folder structure and predictable IDs. Avoid scattering content across route folders if it is logically a collection.
Use the content APIs that match the job:
getCollection() for listsgetEntry() for a single known entrygetEntries() for arrays of referencesExample:
---
import { getCollection } from 'astro:content'
const posts = await getCollection('blog', ({ data }) => !data.draft)
---
When rendering entries, keep route generation and content rendering separate enough that each part remains easy to reason about.
For dynamic routes:
render(entry)Example:
---
import { getCollection, render } from 'astro:content'
export async function getStaticPaths() {
const posts = await getCollection('blog')
return posts.map((post) => ({
params: { slug: post.id },
props: { post },
}))
}
const { post } = Astro.props
const { Content } = await render(post)
---
<article>
<h1>{post.data.title}</h1>
<Content />
</article>
After changing collections:
npx astro sync or the repo’s normal Astro workflowWhen migrating from older content patterns:
src/content/config.ts to src/content.config.tsloader to every collectiontype: 'content' or type: 'data'import { defineCollection, z } from 'astro:content' with import { defineCollection } from 'astro:content' and import { z } from 'astro/zod'post.slug with post.identry.render() with render(entry)getEntryBySlug() and getDataEntryById() with getEntry()If the project is crossing Astro versions at the same time, verify version-sensitive content APIs in the current official Astro docs before finalizing.