feat(feed): Support custom feedUrl for feeds and use it as the self-link in RSS/Atom/JSON; update docs

This commit is contained in:
2025-11-01 03:35:45 +00:00
parent 289483ba0a
commit 4ed892ddc2
5 changed files with 45 additions and 5 deletions

View File

@@ -19,6 +19,8 @@ export interface IFeedOptions {
companyEmail: string;
/** The company website URL (must be absolute) */
companyDomain: string;
/** Optional: Custom URL for the feed's atom:link rel="self" (defaults to https://${domain}/feed.xml) */
feedUrl?: string;
}
/**
@@ -186,7 +188,8 @@ export class Feed {
rss += `<category>${this.escapeXml(this.options.category)}</category>\n`;
// Atom self link
rss += `<atom:link href="https://${this.options.domain}/feed.xml" rel="self" type="application/rss+xml" />\n`;
const selfUrl = this.options.feedUrl || `https://${this.options.domain}/feed.xml`;
rss += `<atom:link href="${selfUrl}" rel="self" type="application/rss+xml" />\n`;
// Items
for (const item of this.items) {
@@ -221,7 +224,8 @@ export class Feed {
atom += `<title>${this.escapeXml(this.options.title)}</title>\n`;
atom += `<subtitle>${this.escapeXml(this.options.description)}</subtitle>\n`;
atom += `<link href="https://${this.options.domain}" />\n`;
atom += `<link href="https://${this.options.domain}/feed.xml" rel="self" />\n`;
const selfUrl = this.options.feedUrl || `https://${this.options.domain}/feed.xml`;
atom += `<link href="${selfUrl}" rel="self" />\n`;
atom += `<updated>${this.formatIso8601Date(new Date())}</updated>\n`;
atom += `<generator>@push.rocks/smartfeed</generator>\n`;
atom += '<author>\n';
@@ -265,7 +269,7 @@ export class Feed {
version: 'https://jsonfeed.org/version/1',
title: this.options.title,
home_page_url: `https://${this.options.domain}`,
feed_url: `https://${this.options.domain}/feed.json`,
feed_url: this.options.feedUrl || `https://${this.options.domain}/feed.json`,
description: this.options.description,
icon: '',
favicon: '',