Generates RSS files for specific document pages with feed.
By default, this plugin generates a blog.xml file in the doc_build/rss/ folder for all pages starting with /blog/.
The RSS file can be accessed via /rss/blog.xml.
This plugin only works with rspress build and does not generate RSS files on rspress dev.
Use the feed.test option to select which pages to be included in the RSS file.
All documents included in the RSS must have either date or published_at in their frontmatter to ensure that the RSS updates are stable on the user side.
Sometimes, you may need to generate multiple RSS files for, e.g., different languages or categories.
You can provide a list of RSS options to the feed option. For instance:
The options above will generate four RSS files: blog.xml, blog-zh.xml, rspack.xml, rsbuild.xml, all located in the rss folder.
You can customize the output path using the output and feed.output parameters.
Please refer to the FeedOutputOptions below.
By default, this plugin will insert a <link rel="alternate"> tag in the selected pages that are included in the RSS, linking to the URL of the RSS file. RSS readers can automatically detect the RSS URL.
If you want to insert this tag in pages that are not included in the RSS (such as the homepage), you can add the link-rss frontmatter to the document, with the value being the feed id. For example:
link-rss also supports inserting multiple <link> tags associated with feed ids on a single page:
The RSS file consists of two parts: the RSS basic information, known as the channel in the RSS format, and the list of articles, known as the item in the RSS format.
Here's how you can cook each part:
channel can be fully modified through the feed parameter. Please refer to the Other Options below.item can be fully modified through the feed.item parameter. Please refer to the item section below.Options of the plugin.
siteUrlstringThe site URL of the current document site. It will be used in the RSS file.
feedFeedChannel | FeedChannel[]{ id: 'blog', test: '/blog/' }Options for RSS file(s). Provide an array to generate multiple RSS files.
See FeedChannel for more information.
outputOmit<FeedOutputOptions, "filename">{ dir: 'rss', type: 'atom' }Options for document output. Please refer to FeedOutputOptions below.
Options for RSS file.
idstringThe ID of an RSS, unique among multiple RSS options. It is also the default file basename for the RSS file.
testRegExp | string | (RegExp | string)[] | ((item: PageIndexInfo, base: string) => boolean)Used to select documents to be included in the RSS. The types are as follows:
RegExp: Regular expression to match the document's route. When the rspress site has base configured, it will match both routes with and without the base path.string: Prefix-based matching to the document's route. When the rspress site has base configured, it will match both routes with and without the base path.(item: PageIndexInfo, base: string) => boolean: Match pages based on page data and frontmatter.item(item: FeedItem, page: PageIndexInfo, siteUrl: string) => FeedItem | PromiseLike<FeedItem>Generates structured data for each article in the RSS file.
Refer to the type of structured data:
The plugin has a built-in generator that utilizes the document's frontmatter and page data.
For example, the content in the RSS will prioritize the summary from frontmatter, and then try the document content.
You can provide the item function to modify the generated data which will be passed as the first parameter to the function you provided.
For example, the following configuration truncates the content of articles in the RSS:
For details on the logic of the built-in generator, please refer to:
outputFeedOutputOptionsoutput option by defaultIn addition to the plugin's output option, there is an additional filename to modify the output filename.
Please refer to FeedOutputOptions below.
FeedChannel also inherits the FeedOptions from the feed package. Please refer to
Output options for RSS files, available at both the top level of the plugin options and the feed level. Using the following type:
Example:
Building with the options above will output two files: feeds/blog.xml and releases/feed.rss.
dirstringrssOutput folder for RSS files, relative to doc_build.
type"atom" | "rss" | "json"atomOutput format of the RSS file, atom by default. Details of these types:
| Value | Format | Default Extension | MIME Type |
|---|---|---|---|
atom |
Atom 1.0 | .xml |
application/atom+xml |
rss |
RSS 2.0 | .rss |
application/rss+xml |
json |
JSON Feed 1.1 | .json |
application/json |
filenamestringModify the full filename of the RSS file.
publicPathstringsiteUrlURL Prefix for the RSS file. An RSS URL is composed of publicPath, dir, and filename.
sortingsorting?: (left: FeedItem, right: FeedItem) => number;Used for sorting the articles. By default, the newest articles go first, followed by the older ones.