From 8c34d810af95fae0ef846f54370a8c88bfab7123 Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Sat, 11 Apr 2026 14:24:49 -0700 Subject: initial commit --- src/utility/feed/atom.ts | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/utility/feed/atom.ts (limited to 'src/utility/feed/atom.ts') diff --git a/src/utility/feed/atom.ts b/src/utility/feed/atom.ts new file mode 100644 index 0000000..d8827e9 --- /dev/null +++ b/src/utility/feed/atom.ts @@ -0,0 +1,87 @@ + + + +/*** 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(""); + } +} -- cgit v1.2.3