Architecture Overview
The blog system is built using several key components:- Content Collections - Type-safe content management using Astro’s content collections API
- Dynamic Routing - Automatic page generation using
[slug].astropattern - Schema Validation - Zod schema ensures all blog posts have required fields
- PostLayout - Consistent layout for all blog posts with author info, tags, and breadcrumbs
Content Collections
Blog posts are stored insrc/content/blog/ and managed through Astro’s content collections system. This provides:
- Type safety - TypeScript types generated from Zod schema
- Validation - Automatic validation of frontmatter fields
- Query API - Simple API to fetch and filter posts
src/content/config.ts:3-16 with a Zod schema that validates:
- Title, description, and author information
- Creation and update timestamps
- Cover image and author avatar URLs
- Publish status and optional tags
Blog Post Structure
Each blog post consists of:- Frontmatter - Metadata in YAML format at the top of the file
- Markdown Content - The actual blog post content using standard Markdown
Dynamic Routing
The blog uses Astro’s dynamic routing with[slug].astro to automatically generate pages:
- Fetches all posts from the blog collection
- Creates a route for each post using its filename as the slug
- Passes the post data as props to the page component
The slug is automatically generated from the filename. For example,
guide-to-geometry-dash.md becomes /blog/guide-to-geometry-dash.Blog Listing Page
The blog index page at/blog displays all published posts. It uses the CardsBlog component to:
- Query all posts from the collection
- Filter by
publish: truestatus - Sort by creation date (newest first)
- Display post cards with images, titles, and metadata
Post Layout Features
ThePostLayout.astro provides a rich reading experience:
- Breadcrumb Navigation - Shows the path from home → blog → post
- Author Information - Displays author name, avatar, and post date
- Tags Display - Shows all tags with visual badges
- Cover Image - Large hero image at the top of the post
- Recent Articles Sidebar - Shows 3 most recent posts
- Social Actions - Like, comment, and share buttons
- Responsive Design - Optimized for mobile and desktop
Next Steps
- Learn about Content Collections - Understand the schema and type safety
- Creating Blog Posts - Step-by-step guide to writing posts
