summaryrefslogtreecommitdiff
path: root/packages/astro-rss/src
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-07-13 16:37:17 -0400
committerGravatar GitHub <noreply@github.com> 2022-07-13 16:37:17 -0400
commitcd2dbfedb15969274df40b1c41b6680ea8885e8d (patch)
tree8927b01efe1d80bd6170ff5834049609cf0cb9dd /packages/astro-rss/src
parent75f202a12416bb9e605110e112c34332c09738aa (diff)
downloadastro-cd2dbfedb15969274df40b1c41b6680ea8885e8d.tar.gz
astro-cd2dbfedb15969274df40b1c41b6680ea8885e8d.tar.zst
astro-cd2dbfedb15969274df40b1c41b6680ea8885e8d.zip
Provide a better error message for when RSS is missing `link` field (#3913)
* Provide a better error message for when RSS is missing `link` field * Adds a changeset
Diffstat (limited to 'packages/astro-rss/src')
-rw-r--r--packages/astro-rss/src/index.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts
index 5f7e63b89..2ff803d8b 100644
--- a/packages/astro-rss/src/index.ts
+++ b/packages/astro-rss/src/index.ts
@@ -113,6 +113,7 @@ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promi
if (typeof rssOptions.customData === 'string') xml += rssOptions.customData;
// items
for (const result of items) {
+ validate(result);
xml += `<item>`;
xml += `<title><![CDATA[${result.title}]]></title>`;
// If the item's link is already a valid URL, don't mess with it.
@@ -146,3 +147,14 @@ export async function generateRSS({ rssOptions, items }: GenerateRSSArgs): Promi
return xml;
}
+
+const requiredFields = Object.freeze(['link', 'title']);
+
+// Perform validation to make sure all required fields are passed.
+function validate(item: RSSFeedItem) {
+ for(const field of requiredFields) {
+ if(!(field in item)) {
+ throw new Error(`@astrojs/rss: Required field [${field}] is missing. RSS cannot be generated without it.`);
+ }
+ }
+}