/*** UTILITY ------------------------------------------ ***/ import { BaseFeed, escapeXML, type FeedOptions } from "./helper.ts"; interface AtomEntry { content?: { body: string; type?: string; }; id: string; image?: string; link: string; summary: string; title: string; updated?: Date; } /*** EXPORT ------------------------------------------- ***/ export class FeedAtom extends BaseFeed { constructor(options: FeedOptions) { super(options); } build(): string { const xmlParts: string[] = [ `\n`, `\n`, ` ${escapeXML(this.options.title)}\n`, ` ${escapeXML(this.options.description)}\n`, ` \n`, ` \n`, ` ${this.options.updated?.toISOString()}\n`, ` ${this.options.generator || "the webb blog"}\n`, ` ${escapeXML(this.options.link)}\n` ]; for (const author of this.options.authors) { xmlParts.push(` \n`); if (author.name) xmlParts.push(` ${escapeXML(author.name)}\n`); if (author.email) xmlParts.push(` ${escapeXML(author.email)}\n`); if (author.link) xmlParts.push(` ${escapeXML(author.link)}\n`); xmlParts.push(` \n`); } if (this.options.icon) { xmlParts.push(` ${escapeXML(this.options.icon)}\n`); xmlParts.push(` ${escapeXML(this.options.icon)}\n`); } if (this.options.feed) xmlParts.push(` \n`); for (const entry of this.items) { xmlParts.push( ` \n`, ` ${escapeXML(entry.title)}\n`, ` \n`, ` ${escapeXML(entry.id)}\n`, ` ${entry.updated?.toISOString() || new Date().toISOString()}\n`, ` ${escapeXML(entry.summary)}\n`, ` ${escapeXML(entry.content?.body || entry.summary)}\n`, entry.image ? ` \n` : "", ` \n` ); } for (const category of this.categories) { xmlParts.push(` \n`); } xmlParts.push(""); return xmlParts.join(""); } }