Making a changelog with Astro

December 21, 2024

In an effort to code-in-the-open, we’re kicking off this changelog by describing…this changelog.

Gaffer Uses Astro

We use Astro for Gaffer’s marketing site and documentation site. It’s fast, simple and easy to use. Deploying the artifacts to Cloudflare Pages has also been easy.

Content Collections Are Awesome

Astro’s content collections API manages structured content. It’s a great way to manage blog posts and documentation. Creating a content collection for MDX changelog entries was as easy adding this ./src/content.config.ts file:

import { glob } from 'astro/loaders';

import { defineCollection, z } from 'astro:content';

const changelog = defineCollection({
    loader: glob({ pattern: '**/*.mdx', base: './src/changelog' }),
    schema: z.object({
        title: z.string(),
        publishedDate: z.coerce.date(),
        description: z.string(),
        tags: z.array(z.string()),
    }),
});

export const collections = {
    changelog,
};

The Challenges

Two issues stood out:

  • While Astro handles MDX pages automatically out of the box, for content collections you’ll need to explicitly add the integration in your astro.config.mjs
  • Prerendering with MDX components requires careful attention to component imports

Sources And Inspirations