Skip to content
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
31 changes: 31 additions & 0 deletions src/__tests__/rss2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,37 @@ describe("rss 2.0", () => {
expect(actual).toMatchSnapshot();
});

it("should emit podcast categories as text attributes", () => {
const podcastFeed = new Feed({
title: "Feed Title",
id: "http://example.com/",
link: "http://example.com/",
podcast: true,
category: "History",
});
const actual = podcastFeed.rss2();
expect(actual).toContain('<itunes:category text="History"/>');
expect(actual).toContain('<googleplay:category text="History"/>');
expect(actual).not.toContain("<itunes:category>History</itunes:category>");
expect(actual).not.toContain("<googleplay:category>History</googleplay:category>");
});

it("should escape & in podcast category attributes", () => {
const podcastFeed = new Feed({
title: "Feed Title",
id: "http://example.com/",
link: "http://example.com/",
podcast: true,
category: "Society & Culture",
});
const actual = podcastFeed.rss2();
// unlike a text node, xml-js does not escape `&` inside an attribute value,
// so it must be escaped before being handed to the serializer
expect(actual).toContain('<itunes:category text="Society &amp; Culture"/>');
expect(actual).toContain('<googleplay:category text="Society &amp; Culture"/>');
expect(actual).not.toContain('text="Society & Culture"');
});

it("should generate a valid feed with video", () => {
const sampleFeed = new Feed({
title: "Feed Title",
Expand Down
10 changes: 7 additions & 3 deletions src/rss2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as convert from "xml-js";
import { generator } from "./config";
import type { Feed } from "./feed";
import type { Author, Category, Enclosure, Extension, Item } from "./typings";
import { sanitizeUrl } from "./utils";
import { sanitize, sanitizeUrl } from "./utils";

export default (ins: Feed) => {
const { options, extensions } = ins;
Expand Down Expand Up @@ -201,8 +201,12 @@ export default (ins: Feed) => {
base.rss._attributes["xmlns:googleplay"] = "http://www.google.com/schemas/play-podcasts/1.0";
base.rss._attributes["xmlns:itunes"] = "http://www.itunes.com/dtds/podcast-1.0.dtd";
if (options.category) {
base.rss.channel["googleplay:category"] = options.category;
base.rss.channel["itunes:category"] = options.category;
base.rss.channel["googleplay:category"] = {
_attributes: { text: sanitize(options.category) },
};
base.rss.channel["itunes:category"] = {
_attributes: { text: sanitize(options.category) },
};
}
if (options.author?.email) {
base.rss.channel["googleplay:owner"] = options.author.email;
Expand Down