Fix missing RSS item customData
(#5591)
* Add failing test. * Fix it. * Add changeset.
This commit is contained in:
parent
9f0fea0ad7
commit
c76e1c8102
3 changed files with 28 additions and 2 deletions
5
.changeset/ninety-socks-chew.md
Normal file
5
.changeset/ninety-socks-chew.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/rss': minor
|
||||
---
|
||||
|
||||
Fixes a bug that prevented an item’s `customData` from being included.
|
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue