Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "isPermaLink" for item:guid #89

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/__tests__/__snapshots__/rss2.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,40 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = `
</rss>"
`;

exports[`rss 2.0 should generate a valid feed with non-HTTP GUIDs 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
<rss version=\\"2.0\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\">
<channel>
<title>Feed Title</title>
<link>http://example.com/</link>
<description>This is my personnal feed!</description>
<lastBuildDate>Sat, 13 Jul 2013 23:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>en</language>
<ttl>60</ttl>
<image>
<title>Feed Title</title>
<url>http://example.com/image.png</url>
<link>http://example.com/</link>
</image>
<copyright>All rights reserved 2013, John Doe</copyright>
<atom:link href=\\"wss://example.com/\\" rel=\\"hub\\"/>
<item>
<title><![CDATA[Hello World 2]]></title>
<link>https://example.com/hello-world-2</link>
<guid>58f618d7a56f2f745291a473
<_attr>
<isPermaLink>false</isPermaLink>
</_attr>
</guid>
<pubDate>Wed, 10 Jul 2013 23:00:00 GMT</pubDate>
<description><![CDATA[This is another article about Hello World.]]></description>
</item>
</channel>
</rss>"
`;

exports[`rss 2.0 should generate a valid feed with video 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
<rss version=\\"2.0\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\">
Expand Down
33 changes: 33 additions & 0 deletions src/__tests__/rss2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,37 @@ describe("rss 2.0", () => {
const actual = sampleFeed.rss2();
expect(actual).toMatchSnapshot();
});
it("should generate a valid feed with non-HTTP GUIDs", () => {
const sampleFeed = new Feed({
title: "Feed Title",
description: "This is my personnal feed!",
link: "http://example.com/",
id: "http://example.com/",
language: "en",
ttl: 60,
image: "http://example.com/image.png",
copyright: "All rights reserved 2013, John Doe",
hub: "wss://example.com/",
updated, // optional, default = today

author: {
name: "John Doe",
email: "[email protected]",
link: "https://example.com/johndoe",
},
})

sampleFeed.addItem({
title: "Hello World 2",
id: "https://example.com/hello-world-2",
link: "https://example.com/hello-world-2",
guid: "58f618d7a56f2f745291a473",
guidIsPermaLink: false,
description: "This is another article about Hello World.",
date: new Date("Sat, 13 Jul 2013 22:00:00 GMT"),
published
});
const actual = sampleFeed.rss2();
expect(actual).toMatchSnapshot();
})
});
8 changes: 8 additions & 0 deletions src/rss2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ export default (ins: Feed) => {

if (entry.guid) {
item.guid = { _text: entry.guid };

/**
* GUID isPermaLink
* https://validator.w3.org/feed/docs/error/InvalidHttpGUID.html
*/
if (entry.guidIsPermaLink !== undefined) {
item.guid._attr = { isPermaLink: entry.guidIsPermaLink };
}
} else if (entry.id) {
item.guid = { _text: entry.id };
} else if (entry.link) {
Expand Down
1 change: 1 addition & 0 deletions src/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Item {
category?: Category[];

guid?: string;
guidIsPermaLink?: boolean;

image?: string | Enclosure;
audio?: string | Enclosure;
Expand Down