Let’s begin by creating a basic scaffold for a blog, so you can compare the difference between a basic blog and the blog format I’m going to show you.
Basic blog anatomy
All blogs need the following 5 properties:
title- a permalink (usually with the
slugattribute) descriptiontags- a published date
The most basic blogs will put all these properties in the frontmatter.
---title: 'My awesome post'slug: my-awesome-postdescription: 'Description for my awesome post'tags: ['tag 1', 'tag 2']pubDate: '2026-02-24'---But slug is not necessary in this case because the file name contains the same information. So we can omit it.
---title: 'My awesome post'description: 'Description for my awesome post'tags: ['tag 1', 'tag 2']pubDate: '2026-02-24'---This is the anatomy of a basic blog.
Static rendering
Blogs should be hosted on static pages because they contain content that doesn’t get changed. They don’t need to be placed behind a server. By using static pages, you also get the benefits of using a CDN.
In the same line of thought, most content on a page can be static. So set the output for Astro to static.
export default defineConfig({ // ... output: 'static',})Basic blog scaffold
You can choose where you want your blog to be, but most people will put it under pages/blog. We’ll do that too.
We’ll create a [slug].astro file that will output the static pages. This [slug] is a placeholder value which we have to populate with getStaticPaths. We will also set slug to the id of each entry from the blog collection.
---export const prerender = false // optional if output is static
// Creates these static pagesexport async function getStaticPaths() { const posts = await getCollection('blog') return posts.map((post, index) => { return { params: { slug: post.id }, // Sets the [slug] param. props: { post }, // Gives you post in Astro.props } })}---Astro will then create one page for every post found in the blog collection. Each of these pages will live at /blog/[slug].
The content from the page can be retrieved by using the props we returned in getStaticPaths. Since this post is an entry from a content collection, we can use render to get the contents within.
---import { render } from 'astro:content'export getStaticPaths() { /* ... */}
// Content on the [slug] pageconst { post } = Astro.propsconst { Content } = await render(post)---
<article> <h1>{post.data.title}</h1> <Content /></article>This is a scaffold you need for the most basic blogs.
Code snippets to copy paste
Here’s everything you need to create basic blog pages.
---import { getCollection, render } from 'astro:content'
export const prerender = false // optional if output is static
export async function getStaticPaths() { const files = await getCollection('blog') return files.map((post, index) => { return { params: { slug: post.id }, props: { post }, } })}
const { post } = Astro.propsconst { Content } = await render(post)---
<article> <h1>{post.data.title}</h1> <Content /></article>Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson