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

Add support for podcast feeds #163

Open
wants to merge 2 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
58 changes: 58 additions & 0 deletions src/__tests__/__snapshots__/rss2.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,61 @@ exports[`rss 2.0 should generate a valid feed with video 1`] = `
</channel>
</rss>"
`;

exports[`rss 2.0 should generate a valid podcast feed with audio 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\\" xmlns:googleplay=\\"http://www.google.com/schemas/play-podcasts/1.0\\" xmlns:itunes=\\"http://www.itunes.com/dtds/podcast-1.0.dtd\\">
<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>
<category>Technology</category>
<atom:link href=\\"wss://example.com/\\" rel=\\"hub\\"/>
<item>
<title><![CDATA[Hello World]]></title>
<link>https://example.com/hello-world?link=sanitized&amp;value=2</link>
<guid>https://example.com/hello-world?id=this&amp;that=true</guid>
<pubDate>Wed, 10 Jul 2013 23:00:00 GMT</pubDate>
<description><![CDATA[This is an article about Hello World.]]></description>
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure url=\\"https://example.com/hello-world.jpg\\" length=\\"0\\" type=\\"image/jpg\\"/>
</item>
<item>
<title><![CDATA[Hello World]]></title>
<link>https://example.com/hello-world3</link>
<guid>https://example.com/hello-world3</guid>
<pubDate>Wed, 10 Jul 2013 23:00:00 GMT</pubDate>
<description><![CDATA[This is an article about Hello World.]]></description>
<content:encoded><![CDATA[Content of my item]]></content:encoded>
<author>[email protected] (Jane Doe)</author>
<author>[email protected] (Joe Smith)</author>
<category>Grateful Dead</category>
<category domain=\\"http://www.fool.com/cusips\\">MSFT</category>
<enclosure length=\\"12665\\" type=\\"audio/mpeg\\" url=\\"https://example.com/hello-world.mp3\\"/>
<itunes:duration>50:00</itunes:duration>
</item>
<googleplay:owner>[email protected]</googleplay:owner>
<itunes:owner>
<itunes:email>[email protected]</itunes:email>
</itunes:owner>
<googleplay:author>John Doe</googleplay:author>
<itunes:author>John Doe</itunes:author>
<googleplay:image href=\\"http://example.com/image.png\\"/>
</channel>
</rss>"
`;
56 changes: 55 additions & 1 deletion src/__tests__/rss2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feed } from "../feed";
import { published, sampleFeed, updated } from "./setup";
import { createSampleFeed, published, sampleFeed, updated } from "./setup";

describe("rss 2.0", () => {
it("should generate a valid feed", () => {
Expand Down Expand Up @@ -158,6 +158,60 @@ describe("rss 2.0", () => {
const actual = sampleFeed.rss2();
expect(actual).toMatchSnapshot();
});
it("should generate a valid podcast feed with audio", () => {
var podcastFeed = createSampleFeed();
podcastFeed.options.podcast = true;

podcastFeed.addItem({
title: "Hello World",
link: "https://example.com/hello-world3",
description: "This is an article about Hello World.",
content: "Content of my item",
author: [
{
name: "Jane Doe",
email: "[email protected]",
link: "https://example.com/janedoe",
},
{
name: "Joe Smith",
email: "[email protected]",
link: "https://example.com/joesmith",
},
],
extensions: [
{
name: "_item_extension_1",
objects: {
about: "just an item extension example",
dummy1: "example",
},
},
{
name: "_item_extension_2",
objects: {
about: "just a second item extension example",
dummy1: "example",
},
},
],
category: [
{
name: "Grateful Dead",
},
{
name: "MSFT",
domain: "http://www.fool.com/cusips",
},
],
date: updated,
audio: { url: "https://example.com/hello-world.mp3", length: 12665, type: "audio/mpeg", duration: 3000 },
published,
});

const actual = podcastFeed.rss2();
expect(actual).toMatchSnapshot();
});
it("should generate a valid feed with video", () => {
const sampleFeed = new Feed({
title: "Feed Title",
Expand Down
196 changes: 101 additions & 95 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,106 +3,112 @@ import { Feed } from "../feed";
export const updated = new Date("Sat, 13 Jul 2013 23:00:00 GMT");
export const published = new Date("Sat, 10 Jul 2013 23:00:00 GMT");

export const sampleFeed = new Feed({
title: "Feed Title",
description: "This is my personnal feed!",
link: "http://example.com/",
id: "http://example.com/",
feed: "http://example.com/sampleFeed.rss",
feedLinks: {
json: "http://example.com/sampleFeed.json",
},
language: "en",
ttl: 60,
image: "http://example.com/image.png",
favicon: "http://example.com/image.ico",
copyright: "All rights reserved 2013, John Doe",
hub: "wss://example.com/",
updated, // optional, default = today
export const createSampleFeed = () => {
var feed = new Feed({
title: "Feed Title",
description: "This is my personnal feed!",
link: "http://example.com/",
id: "http://example.com/",
feed: "http://example.com/sampleFeed.rss",
feedLinks: {
json: "http://example.com/sampleFeed.json",
},
language: "en",
ttl: 60,
image: "http://example.com/image.png",
favicon: "http://example.com/image.ico",
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?link=sanitized&value=2"
}
});
author: {
name: "John Doe",
email: "[email protected]",
link: "https://example.com/johndoe?link=sanitized&value=2"
}
});

sampleFeed.addCategory("Technology");
feed.addCategory("Technology");

sampleFeed.addContributor({
name: "Johan Cruyff",
email: "[email protected]",
link: "https://example.com/johancruyff",
});
feed.addContributor({
name: "Johan Cruyff",
email: "[email protected]",
link: "https://example.com/johancruyff",
});

sampleFeed.addItem({
title: "Hello World",
id: "https://example.com/hello-world?id=this&that=true",
link: "https://example.com/hello-world?link=sanitized&value=2",
description: "This is an article about Hello World.",
content: "Content of my item",
author: [
{
name: "Jane Doe",
email: "[email protected]",
link: "https://example.com/janedoe?link=sanitized&value=2",
},
{
name: "Joe Smith",
email: "[email protected]",
link: "https://example.com/joesmith",
},
{
name: "Joe Smith, Name Only",
}
],
contributor: [
{
name: "Shawn Kemp",
email: "[email protected]",
link: "https://example.com/shawnkemp",
},
{
name: "Reggie Miller",
email: "[email protected]",
link: "https://example.com/reggiemiller",
},
],
extensions: [
{
name: "_item_extension_1",
objects: {
about: "just an item extension example",
dummy1: "example",
feed.addItem({
title: "Hello World",
id: "https://example.com/hello-world?id=this&that=true",
link: "https://example.com/hello-world?link=sanitized&value=2",
description: "This is an article about Hello World.",
content: "Content of my item",
author: [
{
name: "Jane Doe",
email: "[email protected]",
link: "https://example.com/janedoe?link=sanitized&value=2",
},
},
{
name: "_item_extension_2",
objects: {
about: "just a second item extension example",
dummy1: "example",
{
name: "Joe Smith",
email: "[email protected]",
link: "https://example.com/joesmith",
},
{
name: "Joe Smith, Name Only",
}
],
contributor: [
{
name: "Shawn Kemp",
email: "[email protected]",
link: "https://example.com/shawnkemp",
},
{
name: "Reggie Miller",
email: "[email protected]",
link: "https://example.com/reggiemiller",
},
],
extensions: [
{
name: "_item_extension_1",
objects: {
about: "just an item extension example",
dummy1: "example",
},
},
{
name: "_item_extension_2",
objects: {
about: "just a second item extension example",
dummy1: "example",
},
},
],
category: [
{
name: "Grateful Dead",
},
{
name: "MSFT",
domain: "http://www.fool.com/cusips",
},
],
date: updated,
image: "https://example.com/hello-world.jpg",
enclosure: { url: "https://example.com/hello-world.jpg", length: 12665, type: "image/jpeg" },
published,
});

feed.addExtension({
name: "_example_extension",
objects: {
about: "just an extension example",
dummy: "example",
},
],
category: [
{
name: "Grateful Dead",
},
{
name: "MSFT",
domain: "http://www.fool.com/cusips",
},
],
date: updated,
image: "https://example.com/hello-world.jpg",
enclosure: { url: "https://example.com/hello-world.jpg", length: 12665, type: "image/jpeg" },
published,
});
});

return feed;
}

sampleFeed.addExtension({
name: "_example_extension",
objects: {
about: "just an extension example",
dummy: "example",
},
});
export const sampleFeed = createSampleFeed();
Loading