Astro supports fast, automatic RSS feed generation for blogs and other content websites. For more information about RSS feeds in general, see aboutfeeds.com.
Setting up Section titled Setting up @astrojs/rss
@astrojs/rss using your preferred package manager:
Then, ensure you’ve configured a
site in your project’s
astro.config. You will use this to generate links to your RSS articles.
Now, let’s generate our first RSS feed! Create an
rss.xml.js file under your
rss.xml will be the output URL, so feel free to rename this if you prefer.
Next, import the
rss helper from the
@astrojs/rss package and call with the following parameters:
Generating Section titled Generating items
items field accepts a list of RSS feed objects, each with a
pubDate, and optional
customData fields. You can generate this array from a content collection or by using glob imports.
Using content collectionsSection titled Using content collections
To create an RSS feed of pages managed in content collections, you use the
getCollection() function to retrieve the list your of items.
You can configure your collection schema to enforce these expected RSS properties. Import and apply
rssSchema to ensure that each collection entry produces a valid RSS feed item.
Using glob importsSection titled Using glob imports
To create an RSS feed from documents in
src/pages/, use the
pagesGlobToRssItems() helper. This accepts an
import.meta.glob result and outputs an array of valid RSS feed items (see more about writing glob patterns for specifying which pages to include).
This function assumes, but does not verify, that all necessary feed properties are present in each document’s frontmatter. If you encounter errors, verify each page frontmatter manually.
Including full post contentSection titled Including full post content
content key contains the full content of the post as HTML. This allows you to make your entire post content available to RSS feed readers.
When using content collections, render the post
body using a standard Markdown parser like
markdown-it and sanitize the result:
When using glob imports with Markdown, we suggest using the
compiledContent() helper to retrieve the rendered HTML for sanitization. Note: this feature is not supported for MDX files.
Adding a stylesheetSection titled Adding a stylesheet
You can style your RSS feed for a more pleasant user experience when viewing the file in your browser.
stylesheet option to specify an absolute path to your stylesheet.
If you don’t have an RSS stylesheet in mind, we recommend the Pretty Feed v3 default stylesheet, which you can download from GitHub and save into your project’s