diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-11 14:24:49 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-11 14:24:49 -0700 |
| commit | 8c34d810af95fae0ef846f54370a8c88bfab7123 (patch) | |
| tree | 436beaf30f7b2b3f15741dd54a37e313964d1f7d /src/utility/feed/json.ts | |
Diffstat (limited to 'src/utility/feed/json.ts')
| -rw-r--r-- | src/utility/feed/json.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utility/feed/json.ts b/src/utility/feed/json.ts new file mode 100644 index 0000000..589aeae --- /dev/null +++ b/src/utility/feed/json.ts @@ -0,0 +1,41 @@ + + + +/*** UTILITY ------------------------------------------ ***/ + +import { BaseFeed, type FeedOptions } from "./helper.ts"; + +interface JsonItem { + content_html?: string; + date_published?: Date; + id: string; + title: string; + url: string; +} + +/*** EXPORT ------------------------------------------- ***/ + +export class FeedJSON extends BaseFeed<JsonItem> { + constructor(options: FeedOptions) { + super(options); + } + + build(): string { + const json: Record<string, unknown> = { + feed_url: this.options.feed, + home_page_url: this.options.link, + icon: this.options.icon, + items: this.items.map(({ content_html, date_published, id, title, url }) => ({ + ...(content_html && { content_html }), + date_published: date_published?.toISOString() || new Date().toUTCString, + id, + title, + url + })), + title: this.options.title, + version: "https://jsonfeed.org/version/1" + }; + + return JSON.stringify(json, null, 2); + } +} |
