← 전체 글

Astro Content Collections로 블로그 콘텐츠 관리하기

왜 Content Collections인가

Astro의 Content Collections는 src/content/ 아래에 마크다운(또는 MDX) 파일을 두고, zod 스키마로 프론트매터를 검증해주는 기능이다. 블로그처럼 구조화된 글 목록을 다룰 때 파일 시스템 기반 라우팅보다 훨씬 다루기 쉽다.

import { defineCollection, z } from 'astro:content';

const posts = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    date: z.coerce.date(),
    tags: z.array(z.string()).default([]),
  }),
});

export const collections = { posts };

정리