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.
@astrojs/rssusing your preferred package manager:
Create a file in
src/pages/with a name of your choice and the extension
.xml.jsto be used as the output URL for your feed. Some common RSS feed URL names are
The example file below
src/pages/rss.xml.jswill create an RSS feed at
rss()helper from the
@astrojs/rsspackage into your
.xml.jsfile and export a function that returns it using the following parameters:
items field accepts a list of RSS feed objects, each with a required
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
Using content collections
To 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Добавлено в:
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Добавлено в:
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
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.
After 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.