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 = `${site}/- ${site}${phpFeedItem.link}/${site}${phpFeedItem.link}/${new Date(phpFeedItem.pubDate).toUTCString()}
- ${site}${web1FeedItem.link}/${site}${web1FeedItem.link}/${new Date(web1FeedItem.pubDate).toUTCString()}
`;
// prettier-ignore
const validXmlWithContentResult = `${site}/- ${site}${phpFeedItemWithContent.link}/${site}${phpFeedItemWithContent.link}/${new Date(phpFeedItemWithContent.pubDate).toUTCString()}
- ${site}${web1FeedItemWithContent.link}/${site}${web1FeedItemWithContent.link}/${new Date(web1FeedItemWithContent.pubDate).toUTCString()}
`;
+// prettier-ignore
+const validXmlWithCustomDataResult = `${site}/- ${site}${phpFeedItemWithCustomData.link}/${site}${phpFeedItemWithCustomData.link}/${new Date(phpFeedItemWithCustomData.pubDate).toUTCString()}${phpFeedItemWithCustomData.customData}
- ${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 = {