or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

content-integration.mdindex.mdrss-generation.mdschema-validation.md
tile.json

tessl/npm-astrojs--rss

RSS feed generation library for Astro projects with comprehensive configuration options and TypeScript support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@astrojs/rss@4.0.x

To install, run

npx @tessl/cli install tessl/npm-astrojs--rss@4.0.0

index.mddocs/

@astrojs/rss

@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.

Package Information

  • Package Name: @astrojs/rss
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @astrojs/rss

Core Imports

import rss, { getRssString, pagesGlobToRssItems, rssSchema } from "@astrojs/rss";

For CommonJS:

const rss = require("@astrojs/rss").default;
const { getRssString, pagesGlobToRssItems, rssSchema } = require("@astrojs/rss");

Basic Usage

// 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>",
      }
    ],
  });
}

Architecture

@astrojs/rss is built around several key components:

  • Core RSS Generation: Main rss() function that returns HTTP Response with RSS XML
  • String Generation: getRssString() for custom response handling
  • Astro Integration: pagesGlobToRssItems() for converting Astro pages to RSS items
  • Validation System: Zod-based schemas for runtime validation and TypeScript integration
  • XML Builder: Fast-xml-parser based RSS 2.0 compliant XML generation
  • URL Canonicalization: Automatic URL normalization and trailing slash handling

Capabilities

RSS Feed Generation

Core 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;
}

RSS Feed Generation

Content Integration

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>>;

Content Integration

Schema Validation

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;
}>;

Schema Validation

Types

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:

  • At least one of title or description must be provided for each RSS item
  • pubDate accepts Date, string, or number formats and is automatically converted to a Date object
  • source.url must be a valid URL format when provided
  • enclosure.length must be a non-negative integer representing file size in bytes