RSS feed generation library for Astro projects with comprehensive configuration options and TypeScript support
npx @tessl/cli install tessl/npm-astrojs--rss@4.0.0@astrojs/rss is a comprehensive RSS feed generation library for Astro projects. It provides a complete solution for creating RSS 2.0 compliant feeds with support for advanced features like full content inclusion, media enclosures, custom XML namespaces, and TypeScript validation schemas for content collections.
npm install @astrojs/rssimport rss, { getRssString, pagesGlobToRssItems, rssSchema } from "@astrojs/rss";For CommonJS:
const rss = require("@astrojs/rss").default;
const { getRssString, pagesGlobToRssItems, rssSchema } = require("@astrojs/rss");// In an Astro endpoint (e.g., src/pages/rss.xml.js)
import rss from "@astrojs/rss";
export async function GET(context) {
return rss({
title: "My Blog",
description: "A collection of thoughts and ideas",
site: context.site,
items: [
{
title: "First Post",
link: "/posts/first-post",
pubDate: new Date("2023-06-01"),
description: "This is my first blog post",
},
{
title: "Second Post",
link: "/posts/second-post",
pubDate: new Date("2023-06-02"),
description: "Another interesting post",
content: "<h1>Full Content</h1><p>Complete HTML content here</p>",
}
],
});
}@astrojs/rss is built around several key components:
rss() function that returns HTTP Response with RSS XMLgetRssString() for custom response handlingpagesGlobToRssItems() for converting Astro pages to RSS itemsCore RSS feed generation functionality that creates RSS 2.0 compliant XML feeds with comprehensive configuration options.
function rss(options: RSSOptions): Promise<Response>;
function getRssString(options: RSSOptions): Promise<string>;
interface RSSOptions {
title: string;
description: string;
site: string | URL;
items: RSSFeedItem[] | GlobResult;
xmlns?: Record<string, string>;
stylesheet?: string | boolean;
customData?: string;
trailingSlash?: boolean;
}Integration utilities for converting Astro pages and content collections into RSS feed items.
function pagesGlobToRssItems(items: GlobResult): Promise<RSSFeedItem[]>;
type GlobResult = Record<string, () => Promise<any>>;Zod-based validation schemas for TypeScript integration and content collection validation.
const rssSchema: ZodObject<{
title?: string;
description?: string;
pubDate?: Date | string | number;
customData?: string;
categories?: string[];
author?: string;
commentsUrl?: string;
source?: { url: string; title: string };
enclosure?: { url: string; length: number; type: string };
link?: string;
content?: string;
}>;interface RSSFeedItem {
/** Link to item */
link?: string;
/** Full content of the item. Should be valid HTML */
content?: string;
/** Title of item (required if description not provided) */
title?: string;
/** Publication date of item - automatically converted to Date */
pubDate?: Date | string | number;
/** Item description (required if title not provided) */
description?: string;
/** Append some other XML-valid data to this item */
customData?: string;
/** Categories or tags related to the item */
categories?: string[];
/** The item author's email address */
author?: string;
/** A URL of a page for comments related to the item */
commentsUrl?: string;
/** The RSS channel that the item came from */
source?: {
title: string;
url: string;
};
/** A media object that belongs to the item */
enclosure?: {
url: string;
length: number;
type: string;
};
}Important Validation Rules:
title or description must be provided for each RSS itempubDate accepts Date, string, or number formats and is automatically converted to a Date objectsource.url must be a valid URL format when providedenclosure.length must be a non-negative integer representing file size in bytes