To build a post series in Astro, add a series collection, give each post an optional series reference and a part number in its frontmatter, and render a small component that lists every part of the series in order with the current one highlighted. A series index page at /series/<id>/ ties the parts together for readers and search engines.
Key Takeaways
- A
seriescollection holds the title and description once; posts point to it withreference('series').- A
partnumber controls the order, so publish dates can be anything.- One
SeriesNavcomponent shows “Part 2 of 4” and links to every part.- Previous and next links inside a series keep readers moving through it.
Model the series
// src/content.config.ts
import { defineCollection, reference } from 'astro:content';
import { glob, file } from 'astro/loaders';
import { z } from 'astro/zod';
const series = defineCollection({
loader: file('src/data/series.json'),
schema: z.object({
title: z.string(),
description: z.string(),
}),
});
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
pubDate: z.coerce.date(),
series: reference('series').optional(),
part: z.number().int().positive().optional(),
}),
});
export const collections = { series, blog };
[
{
"id": "astro-from-scratch",
"title": "Astro from Scratch",
"description": "A four-part series that builds a blog with Astro, from an empty folder to a deployed site."
}
]
Save the JSON as src/data/series.json. A post joins the series with two lines of frontmatter:
---
# src/content/blog/astro-from-scratch-routing.md
title: "Astro from Scratch, Part 2: Pages and Routing"
pubDate: 2026-11-02
series: astro-from-scratch
part: 2
---
If a post names a series that doesn’t exist, the build fails with a reference error, which keeps typos out of production. The collection references tip explains how references resolve.
Get the parts of a series
Put the lookup in one helper so the navigation box and the index page agree on order:
// src/lib/series.ts
import { getCollection } from 'astro:content';
export async function getSeriesParts(seriesId: string) {
const posts = await getCollection('blog', ({ data }) => data.series?.id === seriesId);
return posts.sort((a, b) => (a.data.part ?? 0) - (b.data.part ?? 0));
}
data.series is a reference object with an id, so the filter compares IDs rather than titles.
Show the series navigation box
---
// src/components/SeriesNav.astro
import { getEntry } from 'astro:content';
import { getSeriesParts } from '../lib/series';
const { post } = Astro.props;
if (!post.data.series) return;
const series = await getEntry(post.data.series);
const parts = await getSeriesParts(post.data.series.id);
const index = parts.findIndex((p) => p.id === post.id);
const prev = parts[index - 1];
const next = parts[index + 1];
---
<nav class="series" aria-label={`Series: ${series.data.title}`}>
<p>
Part {index + 1} of {parts.length} in{' '}
<a href={`/series/${series.id}/`}>{series.data.title}</a>
</p>
<ol>
{parts.map((p) => (
<li>
{p.id === post.id
? <span aria-current="page">{p.data.title}</span>
: <a href={`/blog/${p.id}/`}>{p.data.title}</a>}
</li>
))}
</ol>
<p>
{prev && <a href={`/blog/${prev.id}/`} rel="prev">Previous: {prev.data.title}</a>}
{next && <a href={`/blog/${next.id}/`} rel="next">Next: {next.data.title}</a>}
</p>
</nav>
Drop <SeriesNav post={post} /> into your post layout above or below the content. Posts without a series render nothing, because the component returns early. The position comes from the sorted list rather than the part value itself, so a gap in numbering never shows “Part 3 of 2”. For posts outside a series, the general previous and next links tip uses date order instead.
Add a series index page
---
// src/pages/series/[id].astro
import { getCollection } from 'astro:content';
import { getSeriesParts } from '../../lib/series';
export async function getStaticPaths() {
const all = await getCollection('series');
return Promise.all(
all.map(async (series) => ({
params: { id: series.id },
props: { series, parts: await getSeriesParts(series.id) },
})),
);
}
const { series, parts } = Astro.props;
---
<h1>{series.data.title}</h1>
<p>{series.data.description}</p>
<ol>
{parts.map((p) => <li><a href={`/blog/${p.id}/`}>{p.data.title}</a></li>)}
</ol>
getStaticPaths() can be async and return a promise of the array, which is why the Promise.all() works here. If you announce parts before they’re written, add them as drafts; the draft posts tip shows how to keep them out of production builds. The content docs show where collections sit in a project, and the Blog & Editorial themes are a finished starting point for a series-heavy blog.
FAQ
How do I create a blog post series in Astro?
Add a series collection and give each post a series reference and a part number. Filter posts by series ID, sort by part, and render a navigation component on each post plus an index page per series.
How do I show “Part X of Y” in Astro?
Load all posts in the same series, sort them by part number, and find the current post’s position with findIndex(). The position plus one is X, and the array length is Y.
Can a post belong to more than one series?
Yes. Change the field to series: z.array(reference('series')).optional() and filter with data.series?.some((s) => s.id === seriesId). Render one navigation box per series the post belongs to.
Should a post series use a separate URL structure?
Usually not. Keep posts at their normal /blog/<slug>/ URLs so links survive if the series changes, and add a /series/<id>/ index page that lists the parts.