/*** UTILITY ------------------------------------------ ***/ import { BaseFeed, escapeXML, type FeedOptions } from "./helper.ts"; interface RssItem { content: { body: string; }; description: string; id: string; image?: string; link: string; title: string; updated?: Date; } /*** EXPORT ------------------------------------------- ***/ export class FeedRSS extends BaseFeed { constructor(options: FeedOptions) { super(options); } build(): string { const xmlParts: string[] = [ `\n`, `\n`, ` \n`, ` <![CDATA[${escapeXML(this.options.title)}]]>\n`, ` \n`, ` ${escapeXML(this.options.link)}\n`, ` ${this.options.updated?.toUTCString()}\n`, ` ${this.options.language || "en-US"}\n`, ` ${escapeXML(this.options.generator || "the webb blog")}\n`, ` \n` ]; if (this.options.authors.length > 0) { const authorXml = this.options.authors.map((author) => { const escapedEmail = author.email ? escapeXML(author.email) : ""; const escapedName = author.name ? escapeXML(author.name) : ""; const emailPart = escapedEmail ? `${escapedEmail} ` : ""; return ( ` ${emailPart}(${escapedName})\n` + ` ${emailPart}(${escapedName})\n` ); }).join(""); xmlParts.push(authorXml); } if (this.items.length > 0) { const itemsXml = this.items.map((item) => { const contentXml = item.content ? ` \n` : ""; const imageXml = item.image ? ` \n` : ""; return ( ` \n` + ` ${escapeXML(item.title)}\n` + ` ${escapeXML(item.link)}\n` + ` ${escapeXML(item.id)}\n` + ` ${item.updated?.toUTCString() || new Date().toUTCString()}\n` + ` ${escapeXML(item.description)}\n` + contentXml + imageXml + ` \n` ); }).join(""); xmlParts.push(itemsXml); } xmlParts.push(` \n`, ``); return xmlParts.join(""); } }