diff options
author | 2022-12-13 05:45:35 -0800 | |
---|---|---|
committer | 2022-12-13 08:45:35 -0500 | |
commit | c76e1c810228fb53cd9c34edc73747b0ab64dc28 (patch) | |
tree | 1dba44601e5c6e09b0fb7e2a91c3f21f9c14679d | |
parent | 9f0fea0ad7ef90325c9ff3d2bcc6cfe77c37515d (diff) | |
download | astro-c76e1c810228fb53cd9c34edc73747b0ab64dc28.tar.gz astro-c76e1c810228fb53cd9c34edc73747b0ab64dc28.tar.zst astro-c76e1c810228fb53cd9c34edc73747b0ab64dc28.zip |
Fix missing RSS item `customData` (#5591)
* Add failing test.
* Fix it.
* Add changeset.
-rw-r--r-- | .changeset/ninety-socks-chew.md | 5 | ||||
-rw-r--r-- | packages/astro-rss/src/index.ts | 5 | ||||
-rw-r--r-- | packages/astro-rss/test/rss.test.js | 20 |
3 files changed, 28 insertions, 2 deletions
diff --git a/.changeset/ninety-socks-chew.md b/.changeset/ninety-socks-chew.md new file mode 100644 index 000000000..f24b67cb9 --- /dev/null +++ b/.changeset/ninety-socks-chew.md @@ -0,0 +1,5 @@ +--- +'@astrojs/rss': minor +--- + +Fixes a bug that prevented an item’s `customData` from being included. diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts index 8779ac007..4d87586c3 100644 --- a/packages/astro-rss/src/index.ts +++ b/packages/astro-rss/src/index.ts @@ -163,8 +163,9 @@ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promi if (typeof result.content === 'string') { item['content:encoded'] = result.content; } - if (typeof rssOptions.customData === 'string') - Object.assign(item, parser.parse(`<item>${rssOptions.customData}</item>`).item); + if (typeof result.customData === 'string') { + Object.assign(item, parser.parse(`<item>${result.customData}</item>`).item); + } return item; }); diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index e993d87f3..79f3529f2 100644 --- a/packages/astro-rss/test/rss.test.js +++ b/packages/astro-rss/test/rss.test.js @@ -21,6 +21,10 @@ const phpFeedItemWithContent = { ...phpFeedItem, content: `<h1>${phpFeedItem.title}</h1><p>${phpFeedItem.description}</p>`, }; +const phpFeedItemWithCustomData = { + ...phpFeedItem, + customData: '<dc:creator><![CDATA[Buster Bluth]]></dc:creator>' +}; const web1FeedItem = { // Should support empty string as a URL (possible for homepage route) @@ -41,6 +45,8 @@ const web1FeedItemWithContent = { const validXmlResult = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItem.title}]]></title><link>${site}${phpFeedItem.link}/</link><guid>${site}${phpFeedItem.link}/</guid><description><![CDATA[${phpFeedItem.description}]]></description><pubDate>${new Date(phpFeedItem.pubDate).toUTCString()}</pubDate></item><item><title><![CDATA[${web1FeedItem.title}]]></title><link>${site}${web1FeedItem.link}/</link><guid>${site}${web1FeedItem.link}/</guid><description><![CDATA[${web1FeedItem.description}]]></description><pubDate>${new Date(web1FeedItem.pubDate).toUTCString()}</pubDate></item></channel></rss>`; // prettier-ignore const validXmlWithContentResult = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItemWithContent.title}]]></title><link>${site}${phpFeedItemWithContent.link}/</link><guid>${site}${phpFeedItemWithContent.link}/</guid><description><![CDATA[${phpFeedItemWithContent.description}]]></description><pubDate>${new Date(phpFeedItemWithContent.pubDate).toUTCString()}</pubDate><content:encoded><![CDATA[${phpFeedItemWithContent.content}]]></content:encoded></item><item><title><![CDATA[${web1FeedItemWithContent.title}]]></title><link>${site}${web1FeedItemWithContent.link}/</link><guid>${site}${web1FeedItemWithContent.link}/</guid><description><![CDATA[${web1FeedItemWithContent.description}]]></description><pubDate>${new Date(web1FeedItemWithContent.pubDate).toUTCString()}</pubDate><content:encoded><![CDATA[${web1FeedItemWithContent.content}]]></content:encoded></item></channel></rss>`; +// prettier-ignore +const validXmlWithCustomDataResult = `<?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/"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItemWithCustomData.title}]]></title><link>${site}${phpFeedItemWithCustomData.link}/</link><guid>${site}${phpFeedItemWithCustomData.link}/</guid><description><![CDATA[${phpFeedItemWithCustomData.description}]]></description><pubDate>${new Date(phpFeedItemWithCustomData.pubDate).toUTCString()}</pubDate>${phpFeedItemWithCustomData.customData}</item><item><title><![CDATA[${web1FeedItemWithContent.title}]]></title><link>${site}${web1FeedItemWithContent.link}/</link><guid>${site}${web1FeedItemWithContent.link}/</guid><description><![CDATA[${web1FeedItemWithContent.description}]]></description><pubDate>${new Date(web1FeedItemWithContent.pubDate).toUTCString()}</pubDate><content:encoded><![CDATA[${web1FeedItemWithContent.content}]]></content:encoded></item></channel></rss>`; describe('rss', () => { it('should generate on valid RSSFeedItem array', async () => { @@ -65,6 +71,20 @@ describe('rss', () => { chai.expect(body).xml.to.equal(validXmlWithContentResult); }); + it('should generate on valid RSSFeedItem array with custom data included', async () => { + const { body } = await rss({ + xmlns: { + dc: 'http://purl.org/dc/elements/1.1/', + }, + title, + description, + items: [phpFeedItemWithCustomData, web1FeedItemWithContent], + site, + }); + + chai.expect(body).xml.to.equal(validXmlWithCustomDataResult); + }); + describe('glob result', () => { it('should generate on valid result', async () => { const globResult = { |