Open-Source Wikis

/

Astro

/

Packages

/

@astrojs/rss

withastro/astro

@astrojs/rss

A small library that turns Astro content collections into a valid RSS feed. Published from packages/astro-rss/.

Purpose

Provides a single rss() helper for use in an API route:

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

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

It also exports pagesGlobToRssItems() for the legacy import.meta.glob content workflow and getRssString() for callers that want the XML body without the Response.

Directory layout

packages/astro-rss/
├── src/        # rss(), pagesGlobToRssItems(), getRssString()
├── test/       # mocha unit tests
├── package.json
└── README.md

The implementation uses fast-xml-parser for serialization (notably bumped to 5.3.8 in pnpm-workspace.yaml's minimumReleaseAgeExclude for a security update).

How it works

rss() returns a Response with content-type: application/xml and a body produced by getRssString(). The function:

  1. Validates inputs with a lightweight schema (src/schema.ts).
  2. Optionally enriches items with content collection frontmatter via pagesGlobToRssItems().
  3. Sorts items by pubDate descending.
  4. Renders to RSS 2.0 XML with a Stylesheet directive when xmlns is provided.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

@astrojs/rss – Astro wiki | Factory