← 戻る

Astro 5のContent Collectionsはloaderベースに変更


Astro 5ではContent Collectionsの設定が大きく変わった。

変更点

  • 設定ファイル: src/content/config.tssrc/content.config.ts
  • type: "content" が廃止され、loader が必須に
// Astro 5
import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";

const blog = defineCollection({
  loader: glob({ pattern: "**/*.md", base: "./src/content/blog" }),
  schema: z.object({
    title: z.string(),
    date: z.coerce.date(),
  }),
});

renderも変更

// 旧: post.render()
// 新: import { render } from "astro:content"
import { render } from "astro:content";
const { Content } = await render(post);

post.slug も廃止され、post.id を使う。