Blog Posts
The blog collection allows you to create and manage blog posts using Markdown or MDX files. Blog posts are stored insrc/content/blog/ and support frontmatter metadata for SEO and organization.
Schema Definition
The blog collection is defined insrc/content.config.ts:28-45:
Required Fields
| Field | Type | Description |
|---|---|---|
title | string | Main title of the blog post |
description | string | SEO description and preview text |
pubDate | date | Publication date (automatically coerced to Date) |
draft | boolean | If true, post won’t be published |
Optional Fields
| Field | Type | Description |
|---|---|---|
tags | string[] | Array of tags for categorization |
heroImage | string | Path to the hero/featured image |
publisher | string | Name of the publisher/author |
Example Blog Post
Here’s a real example fromsrc/content/blog/necesito-web.md:1-25:
File Location
Blog posts must be placed in:Supported Formats
- Markdown (
.md): Standard markdown with frontmatter - MDX (
.mdx): Markdown with JSX components for interactive content
Date Handling
ThepubDate field uses z.coerce.date() which automatically converts string dates to JavaScript Date objects. Supported formats:
Creating a New Blog Post
- Create a new
.mdor.mdxfile insrc/content/blog/ - Add frontmatter with required fields:
- Save and the blog post will be automatically loaded by Astro’s content loader
Querying Blog Posts
Use Astro’s content collections API to query blog posts:SEO Best Practices
- Title: Keep under 60 characters for optimal search result display
- Description: 150-160 characters for complete display in search results
- Tags: Use 3-5 relevant tags for better categorization
- Hero Image: Use WebP format for optimal performance (as shown in examples)
- Slug: Create descriptive, keyword-rich URLs
Draft Posts
Setdraft: true to hide posts from production: