summaryrefslogtreecommitdiff
path: root/packages/astro-rss
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro-rss')
-rw-r--r--packages/astro-rss/CHANGELOG.md8
-rw-r--r--packages/astro-rss/README.md10
-rw-r--r--packages/astro-rss/package.json2
-rw-r--r--packages/astro-rss/src/index.ts1
-rw-r--r--packages/astro-rss/src/schema.ts6
-rw-r--r--packages/astro-rss/test/rss.test.js14
-rw-r--r--packages/astro-rss/test/test-utils.js7
7 files changed, 36 insertions, 12 deletions
diff --git a/packages/astro-rss/CHANGELOG.md b/packages/astro-rss/CHANGELOG.md
index 042a36c55..be7c24e33 100644
--- a/packages/astro-rss/CHANGELOG.md
+++ b/packages/astro-rss/CHANGELOG.md
@@ -1,5 +1,13 @@
# @astrojs/rss
+## 4.0.8
+
+### Patch Changes
+
+- [#12137](https://github.com/withastro/astro/pull/12137) [`50dd88b`](https://github.com/withastro/astro/commit/50dd88bc6611243e3f1b2df643af6d0b551fe140) Thanks [@ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes an error that occurred when the optional `pubDate` property was missing in an item.
+
+- [#12137](https://github.com/withastro/astro/pull/12137) [`50dd88b`](https://github.com/withastro/astro/commit/50dd88bc6611243e3f1b2df643af6d0b551fe140) Thanks [@ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes an error where docs incorrectly stated the `title`, `link` and `pubDate` properties of RSS items was required.
+
## 4.0.7
### Patch Changes
diff --git a/packages/astro-rss/README.md b/packages/astro-rss/README.md
index 2a5d6a795..d24c5dabc 100644
--- a/packages/astro-rss/README.md
+++ b/packages/astro-rss/README.md
@@ -198,19 +198,19 @@ const item = {
### `title`
-Type: `string (required)`
+Type: `string (optional)`
-The title of the item in the feed.
+The title of the item in the feed. Optional only if a description is set. Otherwise, required.
### `link`
-Type: `string (required)`
+Type: `string (optional)`
The URL of the item on the web.
### `pubDate`
-Type: `Date (required)`
+Type: `Date (optional)`
Indicates when the item was published.
@@ -218,7 +218,7 @@ Indicates when the item was published.
Type: `string (optional)`
-A synopsis of your item when you are publishing the full content of the item in the `content` field. The `description` may alternatively be the full content of the item in the feed if you are not using the `content` field (entity-coded HTML is permitted).
+A synopsis of your item when you are publishing the full content of the item in the `content` field. The `description` may alternatively be the full content of the item in the feed if you are not using the `content` field (entity-coded HTML is permitted). Optional only if a title is set. Otherwise, required.
### `content`
diff --git a/packages/astro-rss/package.json b/packages/astro-rss/package.json
index d65b71c6d..509f31ee3 100644
--- a/packages/astro-rss/package.json
+++ b/packages/astro-rss/package.json
@@ -1,7 +1,7 @@
{
"name": "@astrojs/rss",
"description": "Add RSS feeds to your Astro projects",
- "version": "4.0.7",
+ "version": "4.0.8",
"type": "module",
"types": "./dist/index.d.ts",
"author": "withastro",
diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts
index b84e81e73..33a8f66a0 100644
--- a/packages/astro-rss/src/index.ts
+++ b/packages/astro-rss/src/index.ts
@@ -70,7 +70,6 @@ const rssOptionsValidator = z.object({
.or(globResultValidator)
.transform((items) => {
if (!Array.isArray(items)) {
- // eslint-disable-next-line
console.warn(
yellow(
'[RSS] Passing a glob result directly has been deprecated. Please migrate to the `pagesGlobToRssItems()` helper: https://docs.astro.build/en/guides/rss/',
diff --git a/packages/astro-rss/src/schema.ts b/packages/astro-rss/src/schema.ts
index 1c2db762d..c4a0fec3f 100644
--- a/packages/astro-rss/src/schema.ts
+++ b/packages/astro-rss/src/schema.ts
@@ -5,9 +5,9 @@ export const rssSchema = z.object({
description: z.string().optional(),
pubDate: z
.union([z.string(), z.number(), z.date()])
- .optional()
- .transform((value) => (value === undefined ? value : new Date(value)))
- .refine((value) => (value === undefined ? value : !isNaN(value.getTime()))),
+ .transform((value) => new Date(value))
+ .refine((value) => !isNaN(value.getTime()))
+ .optional(),
customData: z.string().optional(),
categories: z.array(z.string()).optional(),
author: z.string().optional(),
diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js
index 5a0fd1fd0..8014f87fe 100644
--- a/packages/astro-rss/test/rss.test.js
+++ b/packages/astro-rss/test/rss.test.js
@@ -10,6 +10,7 @@ import {
phpFeedItem,
phpFeedItemWithContent,
phpFeedItemWithCustomData,
+ phpFeedItemWithoutDate,
site,
title,
web1FeedItem,
@@ -25,6 +26,8 @@ const validXmlResult = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
// biome-ignore format: keep in one line
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 isPermaLink="true">${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 isPermaLink="true">${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>`;
// biome-ignore format: keep in one line
+const validXmlResultWithMissingDate = `<?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[${phpFeedItemWithoutDate.title}]]></title><link>${site}${phpFeedItemWithoutDate.link}/</link><guid isPermaLink="true">${site}${phpFeedItemWithoutDate.link}/</guid><description><![CDATA[${phpFeedItemWithoutDate.description}]]></description></item><item><title><![CDATA[${phpFeedItem.title}]]></title><link>${site}${phpFeedItem.link}/</link><guid isPermaLink="true">${site}${phpFeedItem.link}/</guid><description><![CDATA[${phpFeedItem.description}]]></description><pubDate>${new Date(phpFeedItem.pubDate).toUTCString()}</pubDate></item></channel></rss>`;
+// biome-ignore format: keep in one line
const validXmlResultWithAllData = `<?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 isPermaLink="true">${site}${phpFeedItem.link}/</guid><description><![CDATA[${phpFeedItem.description}]]></description><pubDate>${new Date(phpFeedItem.pubDate).toUTCString()}</pubDate></item><item><title><![CDATA[${web1FeedItemWithAllData.title}]]></title><link>${site}${web1FeedItemWithAllData.link}/</link><guid isPermaLink="true">${site}${web1FeedItemWithAllData.link}/</guid><description><![CDATA[${web1FeedItemWithAllData.description}]]></description><pubDate>${new Date(web1FeedItemWithAllData.pubDate).toUTCString()}</pubDate><category>${web1FeedItemWithAllData.categories[0]}</category><category>${web1FeedItemWithAllData.categories[1]}</category><author>${web1FeedItemWithAllData.author}</author><comments>${web1FeedItemWithAllData.commentsUrl}</comments><source url="${web1FeedItemWithAllData.source.url}">${web1FeedItemWithAllData.source.title}</source><enclosure url="${site}${web1FeedItemWithAllData.enclosure.url}" length="${web1FeedItemWithAllData.enclosure.length}" type="${web1FeedItemWithAllData.enclosure.type}"/></item></channel></rss>`;
// biome-ignore format: keep in one line
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 isPermaLink="true">${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 isPermaLink="true">${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>`;
@@ -101,6 +104,17 @@ describe('getRssString', () => {
assertXmlDeepEqual(str, validXmlWithContentResult);
});
+ it('should generate on valid RSSFeedItem array with missing date', async () => {
+ const str = await getRssString({
+ title,
+ description,
+ items: [phpFeedItemWithoutDate, phpFeedItem],
+ site,
+ });
+
+ assertXmlDeepEqual(str, validXmlResultWithMissingDate);
+ });
+
it('should generate on valid RSSFeedItem array with all RSS content included', async () => {
const str = await getRssString({
title,
diff --git a/packages/astro-rss/test/test-utils.js b/packages/astro-rss/test/test-utils.js
index dcc57df21..d3ee8ca33 100644
--- a/packages/astro-rss/test/test-utils.js
+++ b/packages/astro-rss/test/test-utils.js
@@ -4,13 +4,16 @@ export const title = 'My RSS feed';
export const description = 'This sure is a nice RSS feed';
export const site = 'https://example.com';
-export const phpFeedItem = {
+export const phpFeedItemWithoutDate = {
link: '/php',
title: 'Remember PHP?',
- pubDate: '1994-05-03',
description:
'PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994.',
};
+export const phpFeedItem = {
+ ...phpFeedItemWithoutDate,
+ pubDate: '1994-05-03',
+};
export const phpFeedItemWithContent = {
...phpFeedItem,
content: `<h1>${phpFeedItem.title}</h1><p>${phpFeedItem.description}</p>`,