Skip to content

Commit

Permalink
feat: make updated optional on all generators
Browse files Browse the repository at this point in the history
  • Loading branch information
GabsEdits committed Nov 8, 2024
1 parent 3d500fb commit 2b37c42
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface AtomEntry {
title: string;
link: string;
id: string;
updated: Date;
updated?: Date;
image?: string;
summary: string;
content?: {
Expand Down Expand Up @@ -64,7 +64,10 @@ export class AtomFeed extends BaseFeed<AtomEntry> {
` <title>${escapeXml(entry.title)}</title>\n`,
` <link href="${escapeXml(entry.link)}"/>\n`,
` <id>${escapeXml(entry.id)}</id>\n`,
` <updated>${entry.updated.toISOString()}</updated>\n`,
` <updated>${
entry.updated?.toUTCString() ||
new Date().toUTCString()
}</updated>\n`,
` <summary>${escapeXml(entry.summary)}</summary>\n`,
` <content type="${entry.content?.type || "text"}">${
escapeXml(entry.content?.body || entry.summary)
Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface FeedOptions {
};
authors: Array<{
name: string;
email: string;
email?: string;
link?: string;
}>;
copyright?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseFeed, type FeedOptions } from "./common.ts";
interface JsonItem {
title: string;
id: string;
date_published: Date;
date_published?: Date;
content_html?: string;
url: string;
}
Expand Down Expand Up @@ -36,7 +36,7 @@ export class JsonFeed extends BaseFeed<JsonItem> {
id,
title,
url,
date_published: date_published.toISOString(),
date_published: date_published?.toISOString() || new Date().toUTCString,
...(content_html && { content_html }),
})),
};
Expand Down
7 changes: 5 additions & 2 deletions src/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface RssItem {
title: string;
link: string;
id: string;
updated: Date;
updated?: Date;
description: string;
content: {
body: string;
Expand Down Expand Up @@ -70,7 +70,10 @@ export class RssFeed extends BaseFeed<RssItem> {
` <title>${escapeXml(item.title)}</title>\n` +
` <link>${escapeXml(item.link)}</link>\n` +
` <guid>${escapeXml(item.id)}</guid>\n` +
` <pubDate>${item.updated.toUTCString()}</pubDate>\n` +
` <pubDate>${
item.updated?.toUTCString() ||
new Date().toUTCString()
}</pubDate>\n` +
` <description>${escapeXml(item.description)}</description>\n` +
contentXml +
imageXml +
Expand Down

0 comments on commit 2b37c42

Please sign in to comment.