Frontend2025년 8월 30일2분 읽기

Content Layer — 마크다운 기반 콘텐츠 관리

YS
YoungSam
조회 2088

Astro Content Collections

// src/content/config.ts
import { defineCollection, z } from "astro:content";

const blog = defineCollection({
  schema: z.object({
    title: z.string(),
    date: z.date(),
    tags: z.array(z.string()),
    draft: z.boolean().default(false),
  }),
});

export const collections = { blog };

사용

---
import { getCollection } from "astro:content";
const posts = await getCollection("blog", ({ data }) => !data.draft);
---
{posts.map(post => <PostCard post={post} />)}

마크다운 파일이 타입 안전한 데이터 소스가 됩니다.

Content LayerMarkdownCMS

댓글 0

아직 댓글이 없습니다.