Skip to content

Commit a99486d

Browse files
committed
feat: add support for author link
And make sure email is optional
1 parent 9c50fe2 commit a99486d

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const atomFeed = new Atom({
5151
authors: [
5252
{
5353
name: "John Doe",
54-
5554
},
5655
],
5756
id: "https://example.com/atom-feed",

src/atom.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ export class AtomFeed extends BaseFeed<AtomEntry> {
4242
xmlParts.push(
4343
` <author>\n`,
4444
` <name>${escapeXml(author.name)}</name>\n`,
45-
` <email>${escapeXml(author.email)}</email>\n`,
46-
` </author>\n`,
4745
);
46+
47+
if (author.email) {
48+
xmlParts.push(` <email>${escapeXml(author.email)}</email>\n`);
49+
}
50+
51+
if (author.link) {
52+
xmlParts.push(` <uri>${escapeXml(author.link)}</uri>\n`);
53+
}
54+
55+
xmlParts.push(` </author>\n`);
4856
}
4957

5058
if (this.options.icon) {

src/rss.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ export class RssFeed extends BaseFeed<RssItem> {
4444

4545
if (this.options.authors.length > 0) {
4646
const authorXml = this.options.authors.map((author) => {
47-
const escapedEmail = escapeXml(author.email);
47+
const escapedEmail = author.email ? escapeXml(author.email) : "";
4848
const escapedName = escapeXml(author.name);
49+
const emailPart = escapedEmail ? `${escapedEmail} ` : "";
4950
return (
50-
` <webMaster>${escapedEmail} (${escapedName})</webMaster>\n` +
51-
` <author>${escapedEmail} (${escapedName})</author>\n` +
52-
` <managingEditor>${escapedEmail} (${escapedName})</managingEditor>\n`
51+
` <webMaster>${emailPart}(${escapedName})</webMaster>\n` +
52+
` <author>${emailPart}(${escapedName})</author>\n` +
53+
` <managingEditor>${emailPart}(${escapedName})</managingEditor>\n`
5354
);
5455
}).join("");
5556
xmlParts.push(authorXml);

test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Deno.test("Atom Feed Generation", () => {
8080
authors: [
8181
{
8282
name: "John Doe",
83-
8483
link: "https://example.org",
8584
},
8685
],
@@ -110,13 +109,13 @@ Deno.test("Atom Feed Generation", () => {
110109
<generator>Feed for Deno</generator>
111110
<author>
112111
<name>John Doe</name>
113-
<email>test@example.org</email>
112+
<uri>https://example.org</uri>
114113
</author>
115114
<entry>
116115
<title>First Atom Item</title>
117116
<link href="http://example.com/atom1"/>
118117
<id>1</id>
119-
<updated>2024-10-19T15:12:56.000Z</updated>
118+
<updated>Sat, 19 Oct 2024 15:12:56 GMT</updated>
120119
<summary>Summary for Atom item 1</summary>
121120
<content type="html">Content for Atom item 1</content>
122121
</entry>

0 commit comments

Comments
 (0)