Add an RSS feed
Astro supports fast, automatic RSS feed generation for blogs and other content websites. RSS feeds provide an easy way for users to subscribe to your content.
Setting up @astrojs/rss
Section titled Setting up @astrojs/rssThe package @astrojs/rss
provides helpers for generating RSS feeds using API endpoints. This unlocks both static builds and on-demand generation when using an SSR adapter.
- Install
@astrojs/rss
using your preferred package manager:
- Create a file in
src/pages/
with a name of your choice and the extension.xml.js
to be used as the output URL for your feed. Some common RSS feed URL names arefeed.xml
orrss.xml
.
The example file below src/pages/rss.xml.js
will create an RSS feed at site/rss.xml
.
- Import the
rss()
helper from the@astrojs/rss
package into your.xml.js
file and export a function that returns it using the following parameters:
Generating items
Section titled Generating itemsThe items
field accepts a list of RSS feed objects, each with a required link
, title
, and pubDate
. Three optional values may also be included description
(a short excerpt), content
(the full content of your post), and a customData
field for including any extra data, such as other frontmatter properties from your blog posts.
You can generate this array from a content collection schema or by using glob imports for blog posts located within src/pages/
.
Using content collections
Section titled Using content collectionsTo create an RSS feed of pages managed in content collections, use the getCollection()
function to retrieve the list of your items.
Optional: replace your existing blog collection schema to enforce the expected RSS properties.
To ensure that every blog entry produces a valid RSS feed item, you can optionally import and apply rssSchema
instead of defining each individual property of your schema.
Using glob imports
Section titled Using glob imports@astrojs/rss@2.1.0
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).
Including full post content
Section titled Including full post contentastro@1.6.14
The 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, you may use the compiledContent()
helper to retrieve the rendered HTML for sanitization. Note: this feature is not supported for MDX files.
Adding a stylesheet
Section titled Adding a stylesheetStyle your RSS feed for a more pleasant user experience when viewing the file in your browser.
Use the rss
function’s stylesheet
option to specify an absolute path to your stylesheet.
Next Steps
Section titled Next StepsAfter visiting your feed in the browser at your-domain.com/rss.xml
and confirming that you can see data for each of your posts, you can now promote your feed on your website. Adding the standard RSS icon to your site lets your readers know that they can subscribe to your posts in their own feed reader.
Resources
Section titled ResourcesMore recipes
-
Share State Between Islands
Learn how to share state across framework components with Nano Stores.
-
Add an RSS feed
Add an RSS feed to your Astro site to let users subscribe to your content.
-
Installing a Vite or Rollup plugin
Learn how you can import YAML data by adding a Rollup plugin to your project.
-
Build Forms With API Routes
Learn how to use JavaScript to send form submissions to an API Route
-
Build HTML Forms in Astro Pages
Learn how to build HTML forms and handle submissions in your frontmatter
-
Use Bun with Astro
Learn how to use Bun with your Astro site.
-
Call endpoints from the server
Learn how to call endpoints from the server in Astro.
-
Verify a Captcha
Learn how to create an API route and fetch it from the client.
-
Build your Astro Site with Docker
Learn how to build your Astro site using Docker.
-
Add icons to external links
Learn how to install a rehype plugin to add icons to external links in your Markdown files
-
Add i18n features
Use dynamic routing and content collections to add internationalization support to your Astro site.
-
Add Last Modified Time
Build a remark plugin to add the last modified time to your Markdown and MDX.
-
Add Reading Time
Build a remark plugin to add reading time to your Markdown or MDX files.
-
Share State Between Astro Components
Learn how to share state across Astro components with Nano Stores.