RSS feeds
Stati writes RSS 2.0 feeds during production builds (stati build), never in stati dev. A site can have several feeds, each with its own content selection.
Basic configuration
Enable RSS feed generation in your stati.config.ts:
import { defineConfig } from '@stati/core';
export default defineConfig({
site: {
title: 'My Blog',
baseUrl: 'https://example.com',
},
rss: {
enabled: true,
feeds: [
{
filename: 'feed.xml',
title: 'My Blog Posts',
description: 'Latest articles from my blog',
},
],
},
});
This minimal configuration will generate a feed.xml file containing all your pages, including index pages such as the home page. To leave a listing page out, exclude its file, such as excludePatterns: ['**/blog/index.md']. A pattern like '**/index.md' also drops posts written as post-name/index.md.
Stati does not link the feed from your pages. Add a link to the <head> of your layout:
<link rel="alternate" type="application/rss+xml" title="My Blog Posts" href="<%= stati.url('/feed.xml') %>">
Content filtering
Filter by directory
Use contentPatterns to include only specific content:
rss: {
enabled: true,
feeds: [
{
filename: 'blog.xml',
title: 'Blog Feed',
description: 'Latest blog posts',
contentPatterns: ['**/blog/**'], // Only pages in a blog/ folder
},
],
}
How patterns match:
contentPatternsandexcludePatternsare tested against each page’s source file path, which is an absolute path such as/home/me/my-site/site/blog/post.md. Start folder patterns with**/('**/blog/**'). A pattern like'blog/**'or'site/blog/**'matches nothing and produces an empty feed. Patterns without*or?must equal the path or be a prefix of it, so prefer glob patterns.**/blog/**also matchesblog/index.md; addexcludePatterns: ['**/blog/index.md']to leave the listing page out. An emptycontentPatternsarray includes every page. Pages created from a[param].mdtemplate, the later pages of a paginated listing and the 404 page are never in a feed, whatever the patterns.
Exclude patterns
Use excludePatterns to exclude specific content:
rss: {
enabled: true,
feeds: [
{
filename: 'feed.xml',
title: 'Main Feed',
description: 'All content except draft-* files',
excludePatterns: ['**/draft-*', '**/blog/index.md'],
},
],
}
Custom filter function
For fine-grained control, use a custom filter function:
rss: {
enabled: true,
feeds: [
{
filename: 'featured.xml',
title: 'Featured Posts',
description: 'Hand-picked featured articles',
filter: (page) => page.frontMatter.featured === true,
},
],
}
Multiple feeds
You can create multiple feeds targeting different content:
rss: {
enabled: true,
feeds: [
{
filename: 'feed.xml',
title: 'All Posts',
description: 'All blog posts and articles',
},
{
filename: 'blog.xml',
title: 'Blog Posts',
description: 'Latest blog posts',
contentPatterns: ['**/blog/**'],
maxItems: 20,
},
{
filename: 'news.xml',
title: 'News Feed',
description: 'Latest news updates',
contentPatterns: ['**/news/**'],
maxItems: 10,
},
],
}
Feed metadata
Customize your feed with optional metadata:
{
filename: 'feed.xml',
title: 'My Blog',
description: 'Articles about web development',
// Optional metadata
language: 'en-US',
copyright: 'Copyright 2025 My Company',
category: 'Technology',
ttl: 60, // Cache for 60 minutes
// Managing editor
managingEditor: '[email protected] (Jane Doe)',
// Webmaster
webMaster: '[email protected] (John Smith)',
// Feed image
image: {
url: 'https://example.com/logo.png',
title: 'Site Logo',
link: 'https://example.com',
width: 144,
height: 144,
},
}
Sorting and limiting
Sort order
Control the order of items in your feed:
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts',
sortBy: 'date-desc', // Options: 'date-desc', 'date-asc', 'title-asc', 'title-desc', 'custom'
}
Custom sort function
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts',
sortBy: 'custom',
sortFn: (a, b) => {
// Custom sorting logic
const priorityA = Number(a.frontMatter.priority ?? 0);
const priorityB = Number(b.frontMatter.priority ?? 0);
return priorityB - priorityA; // Higher priority first
},
}
Limit items
Limit the number of items in a feed:
{
filename: 'feed.xml',
title: 'Recent Posts',
description: 'Last 10 posts',
maxItems: 10,
}
Field mapping
Customize how page data maps to RSS feed items:
Default mapping
By default, Stati uses these front matter fields:
-
title→ RSS item title -
description→ RSS item description -
publishedAt,published,dateorcreatedAt(first valid one) → RSS item pubDate -
author→ RSS item author -
tags→ RSS item categories -
author→ RSS item author. Text is used as written; an object is written asemail (name), or as just the email or name when it has only one of them. A list of authors is joined with commas:author: name: Jane Doe email: [email protected]
Custom field names
Map to different front matter fields:
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts',
itemMapping: {
title: 'headline', // Use 'headline' instead of 'title'
description: 'excerpt', // Use 'excerpt' instead of 'description'
pubDate: 'publishDate', // Use 'publishDate' instead of the default date fields
author: 'authorName', // Use 'authorName' instead of 'author'
category: 'categories', // Use 'categories' instead of 'tags'
},
}
Field mapping functions
Use functions for custom transformations:
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts',
itemMapping: {
// Transform title
title: (page) => `${page.frontMatter.title} - My Blog`,
// Build custom description
description: (page) =>
String(page.frontMatter.excerpt || page.frontMatter.description || 'Read more...'),
// Custom author format
author: (page) => {
const author = page.frontMatter.author;
const email = page.frontMatter.email;
return email ? `${email} (${author})` : undefined;
},
// Custom link
link: (page, config) =>
`${config.site.baseUrl}${page.url}?utm_source=rss`,
},
}
An item’s guid defaults to its link, so a custom link changes the guid too. Set itemMapping.guid to keep it stable.
A link or guid function can return any text. A link that isn’t an absolute URL is resolved against site.baseUrl, as are the feed’s link, the image URLs and an enclosure’s url; a protocol-relative URL (//cdn.example.com/a.mp3) gets the scheme of site.baseUrl. The <guid> is marked as a permalink (isPermaLink="true") only when it is an absolute http or https URL; any other value, such as urn:post:42, is written with isPermaLink="false".
When a callback fails
A callback that throws for one page doesn’t stop the feed. Stati logs a warning that names the feed and the page, and leaves out what failed:
link: the item is skipped, since Stati can’t know where it points.title,description,pubDate,authorandcategory,guid,enclosureandcustomItemElements: the item stays and only that field is left out.
A callback that fails for the whole feed, such as a filter or sortFn that throws, skips that feed and logs an error. The other feeds are still written, and the build finishes. The skipped feed’s file from an earlier build stays in dist/ unless you build with --clean.
Include full content
Include each page’s body in its feed item:
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts with full content',
itemMapping: {
includeContent: true, // Put the page body in <description>
},
}
Note:
includeContentuses the page’s Markdown source (the text after the front matter), not rendered HTML. It is written inside a CDATA section in<description>. Feed readers that expect HTML will show the Markdown as plain text. A]]>in the body is split across two CDATA sections, so the feed stays valid XML and readers get the body unchanged. A page whose body is empty or only whitespace gets itsdescriptioninstead.
Advanced features
Custom namespaces
Add custom XML namespaces for RSS extensions:
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts',
namespaces: {
'content': 'http://purl.org/rss/1.0/modules/content/',
'dc': 'http://purl.org/dc/elements/1.1/',
},
}
Custom item elements
Add custom XML elements to each item:
{
filename: 'feed.xml',
title: 'My Feed',
description: 'Latest posts',
customItemElements: (page) => ({
'dc:creator': String(page.frontMatter.author ?? ''),
'custom:readTime': `${page.readingTime} min`,
}),
}
Values are converted to strings and HTML-escaped; undefined and null values are skipped. Declare any prefix you use (dc:, custom:) in namespaces. A key that isn’t a valid XML element name ('read time', or anything starting with xml) is skipped with a warning.
Enclosures (media files)
Add enclosures for podcasts or other media:
{
filename: 'podcast.xml',
title: 'My Podcast',
description: 'Latest podcast episodes',
enclosure: (page) => {
if (page.frontMatter.audioUrl) {
return {
url: String(page.frontMatter.audioUrl),
length: Number(page.frontMatter.audioSize), // Size in bytes
type: 'audio/mpeg',
};
}
return undefined;
},
}
length is the file size in bytes. RSS requires it, so a missing or invalid value is written as 0. An enclosure without a url is left out with a warning.
Configuration validation
Stati automatically validates your RSS configuration during the build process. If validation reports any error, Stati logs the errors and generates no feeds for that build; the rest of the build continues. Warnings are logged and the feeds are still generated.
To validate a config in your own code, use validateRSSConfig().
Validation rules
Errors (no feed is generated while any error remains):
- Missing required fields (
filename,title,description) - Invalid TTL value (must be non-negative)
- Invalid
maxItemsvalue (must be a positive number) - Invalid
sortByvalue (must be one of:date-desc,date-asc,title-asc,title-desc,custom) - Missing
sortFnwhensortByiscustom - Duplicate feed filenames
- Missing image fields when image is specified
- An empty
feedsarray
Warnings (informational only):
- Email addresses not in correct format
- Image dimensions exceeding RSS 2.0 recommendations (144×400 max)
- Filename not ending in
.xml - TTL set to 0 (no caching)
- Empty content patterns array
Troubleshooting
Feed not generated
If your feed isn’t being generated:
- Check environment: Ensure you’re running a production build (
npm run build, notnpm run dev) - Verify enabled: Ensure
rss.enabled: truein your config - Check feed config: Verify your feed has required fields (
filename,title,description) - Check validation errors: Look for validation errors in the build output
- Check content patterns: If using
contentPatterns, ensure they match your content - Check maxItems:
maxItemsmust be 1 or more;0fails validation, and then no feed is written
Empty feed
If your feed is empty:
- Check content patterns: Patterns are matched against absolute source file paths, so folder patterns need a leading
**/('**/blog/**', not'blog/**') - Check exclude patterns: Ensure you’re not excluding all content
- Check filter function: Verify your custom filter isn’t too restrictive
Invalid XML
If your feed has XML errors:
- Check special characters: Stati escapes XML characters, and leaves out control characters (other than tabs and line breaks) that XML can’t hold
- Check custom elements: Ensure custom elements use valid XML tag names
- Validate feed: Use an RSS validator to check your feed
Next steps
- Learn about SEO configuration
- Configure Sitemap generation
- Explore Build hooks