feed icon indicating copy to clipboard operation
feed copied to clipboard

feat(atom/rss/json): support language and on feed and feed items (#196)

Open marcojakob opened this issue 8 months ago β€’ 0 comments

Overview

This PR implements comprehensive language support across all feed formats (Atom 1.0, JSON Feed 1.1, and RSS 2.0), addressing issue #196 which requested language support in Atom feeds. The implementation goes beyond the original request to provide consistent language functionality across all supported feed formats.

What's New

Atom 1.0 Language Support

  • Feed-level language: Added xml:lang attribute to <feed> element when language is specified
  • Per-item language: Individual <entry> elements can have their own xml:lang attributes
  • Security: Language values are properly sanitized to prevent XML injection attacks
  • Standards compliance: Follows Atom 1.0 specification for language declarations

JSON Feed 1.1 Enhancement

  • Upgraded to JSON Feed 1.1: Updated from version 1.0 to support the language field
  • Feed-level language: Added language field to top-level feed object
  • Per-item language: Individual items can specify their own language
  • Backward compatibility: Maintains compatibility while adding new features

RSS 2.0 Verification

  • Confirmed existing support: RSS 2.0 already had channel-level <language> element support
  • Added test coverage: Comprehensive tests for RSS language functionality
  • Documented limitations: RSS 2.0 spec doesn't support per-item language (by design)

Technical Implementation

Type System Updates

  • Added language?: string to the Item interface for per-item language support
  • Existing FeedOptions.language field was already present and working

Security Enhancements

  • Language attributes are sanitized using the existing sanitize() function
  • Prevents XML/XSS injection attacks via malformed language codes

Standards Compliance

  • Atom: Uses xml:lang attributes as per W3C Atom specification
  • JSON Feed: Follows JSON Feed 1.1 specification for language support
  • RSS: Respects RSS 2.0 limitations (channel-level only)

Testing

Created dedicated test files for maintainability:

  • atom1.language.test.ts
  • json.language.test.ts
  • rss2.language.test.ts

Test Coverage Includes:

  • Feed-level and item-level language support
  • Multiple language codes (en, fr, es-ES, zh-CN, ja-JP, pt-BR, etc.)
  • Security testing with malicious input
  • Edge cases and validation
  • Format-specific behavior verification

Language Support Matrix

Format Feed-Level Item-Level Implementation Status
Atom 1.0 βœ… xml:lang βœ… xml:lang Complete
JSON Feed 1.1 βœ… language βœ… language Complete
RSS 2.0 βœ… <language> ❌ Spec limitation Complete

Usage Examples

Basic Feed-Level Language

const feed = new Feed({
  title: "My Blog",
  language: "en-US", // Now supported across all formats
  // ... other options
});

Per-Item Language Support

feed.addItem({
  title: "Article en FranΓ§ais",
  language: "fr-FR", // Atom & JSON Feed only
  // ... other item properties
});

Related Issues

  • Closes #196 (language should be supported in atom feeds)
  • Enhances overall feed internationalization support

marcojakob avatar Aug 24 '25 18:08 marcojakob