Building a Blog with Astro
Shore · · 2 min read
In this post, I’ll walk through the tech stack and design decisions behind this blog.
The Tech Stack
This blog is built with:
- Astro - The web framework for content-driven websites
- Tailwind CSS v4 - Utility-first CSS framework
- React - For interactive components (theme toggle, progress bar)
- Cloudflare Pages - Fast, global hosting with automatic deployments
Project Structure
The project follows a clean, organized structure:
src/
├── blog/ # Markdown blog posts
├── components/ # Reusable UI components
├── layouts/ # Page layouts
├── pages/ # Route handlers
└── styles/ # Global and typography styles
Content Collections
Astro’s Content Collections make managing blog posts a breeze:
const blogs = defineCollection({
loader: glob({ pattern: '**/[^_]*.md', base: './src/blog' }),
schema: z.object({
slug: z.string(),
title: z.string(),
description: z.string(),
date: z.date(),
author: z.string(),
tags: z.array(z.string()),
featured: z.boolean(),
}),
});
Dark Mode
The site supports both light and dark modes:
- Checks localStorage for saved preference
- Falls back to system preference
- Persists user choice across sessions
Performance
Astro ships minimal JavaScript by default. The only client-side JS is for:
- Theme toggle functionality
- Reading progress bar
- Prefetching links for faster navigation
Deployment
Cloudflare Pages makes deployment simple:
- Connect your GitHub repository
- Set build command:
npm run build - Set output directory:
dist - Deploy automatically on every push
Conclusion
Astro provides an excellent foundation for building fast, content-focused websites. The combination with Tailwind CSS and Cloudflare Pages creates a powerful, modern stack.
Feel free to explore the source code and use it as inspiration for your own projects!