New

Launch your link-in-bio page in minutes Linkk

How to add an RSS feed to your Astro site

Learn how to set up a fully functional RSS feed in Astro. Perfect for blogs and content websites looking to boost discoverability and support subscriptions.

Nathan Lawson

Want readers to subscribe to your blog via RSS? Astro makes it easy with the @astrojs/rss package. With just a few lines of code, you can generate a fast, standards-compliant RSS feed that keeps your audience in the loop.


1. Install @astrojs/rss

First, add the package to your project:

pnpm add @astrojs/rss

Make sure your astro.config.mjs includes a site URL — it’s required to generate full links:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  site: 'https://example.com', // replace with your site
});

2. Create the RSS feed file

Create a new file in src/pages/ called rss.xml.js (or feed.xml.js). This will be your feed endpoint.

// src/pages/rss.xml.js
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';

export async function GET(context) {
  const posts = await getCollection('blog');
  return rss({
    title: 'My Blog',
    description: 'Latest posts from my Astro site',
    site: context.site,
    items: posts.map((post) => ({
      title: post.data.title,
      description: post.data.description,
      pubDate: post.data.pubDate,
      link: `/blog/${post.id}/`,
    })),
  });
}

Your feed will now be available at /rss.xml.


3. Enable autodiscovery

Add this tag inside your <head> to make it easier for browsers and RSS readers to find your feed:

<link
  rel="alternate"
  type="application/rss+xml"
  title="My Blog Feed"
  href={new URL('rss.xml', Astro.site)}
/>

4. Optional: Use RSS schema for validation

If you want to enforce correct frontmatter for all blog posts, use rssSchema in your content.config.ts:

// src/content/config.ts
import { defineCollection } from 'astro:content';
import { rssSchema } from '@astrojs/rss';

const blog = defineCollection({
  schema: rssSchema,
});

export const collections = { blog };

Already built into our blazing-fast themes

Every Astro theme from astrothem.es includes a fully working RSS feed. That means your blog is ready to syndicate the moment you deploy. No extra setup needed.

Check out our themes and start building a performant, subscription-ready Astro blog today.

Tags

astro tutorials rss
<Layout>
  <header class="astro-fast">
    <nav>...</nav>
  </header>
  <main>
    <Hero client:idle />
    <Features />
    <Testimonials />
    <Pricing client:visible />
  </main>
  <footer>...</footer>
</Layout>
Premium Themes

Build blazing-fast websites with astrothem.es

Production-ready themes optimized for performance and designed to save you weeks of development time.

Linkk Theme Preview
Lightning Fast