From c76e1c810228fb53cd9c34edc73747b0ab64dc28 Mon Sep 17 00:00:00 2001 From: Matt Stein Date: Tue, 13 Dec 2022 05:45:35 -0800 Subject: [PATCH] Fix missing RSS item `customData` (#5591) * Add failing test. * Fix it. * Add changeset. --- .changeset/ninety-socks-chew.md | 5 +++++ packages/astro-rss/src/index.ts | 5 +++-- packages/astro-rss/test/rss.test.js | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .changeset/ninety-socks-chew.md 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(`${rssOptions.customData}`).item); + if (typeof result.customData === 'string') { + Object.assign(item, parser.parse(`${result.customData}`).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: `

${phpFeedItem.title}

${phpFeedItem.description}

`, }; +const phpFeedItemWithCustomData = { + ...phpFeedItem, + customData: '' +}; const web1FeedItem = { // Should support empty string as a URL (possible for homepage route) @@ -41,6 +45,8 @@ const web1FeedItemWithContent = { const validXmlResult = `<![CDATA[${title}]]>${site}/<![CDATA[${phpFeedItem.title}]]>${site}${phpFeedItem.link}/${site}${phpFeedItem.link}/${new Date(phpFeedItem.pubDate).toUTCString()}<![CDATA[${web1FeedItem.title}]]>${site}${web1FeedItem.link}/${site}${web1FeedItem.link}/${new Date(web1FeedItem.pubDate).toUTCString()}`; // prettier-ignore const validXmlWithContentResult = `<![CDATA[${title}]]>${site}/<![CDATA[${phpFeedItemWithContent.title}]]>${site}${phpFeedItemWithContent.link}/${site}${phpFeedItemWithContent.link}/${new Date(phpFeedItemWithContent.pubDate).toUTCString()}<![CDATA[${web1FeedItemWithContent.title}]]>${site}${web1FeedItemWithContent.link}/${site}${web1FeedItemWithContent.link}/${new Date(web1FeedItemWithContent.pubDate).toUTCString()}`; +// prettier-ignore +const validXmlWithCustomDataResult = `<![CDATA[${title}]]>${site}/<![CDATA[${phpFeedItemWithCustomData.title}]]>${site}${phpFeedItemWithCustomData.link}/${site}${phpFeedItemWithCustomData.link}/${new Date(phpFeedItemWithCustomData.pubDate).toUTCString()}${phpFeedItemWithCustomData.customData}<![CDATA[${web1FeedItemWithContent.title}]]>${site}${web1FeedItemWithContent.link}/${site}${web1FeedItemWithContent.link}/${new Date(web1FeedItemWithContent.pubDate).toUTCString()}`; 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 = {