diff options
author | 2024-01-06 08:47:29 +0100 | |
---|---|---|
committer | 2024-01-06 07:47:29 +0000 | |
commit | 24663c9695385fed9ece57bf4aecdca3a8581e70 (patch) | |
tree | dee0e5f50670a2f897b483fc181cc98461294f6f /packages/astro-rss/src/schema.ts | |
parent | edc87abd476a5b32cdc9ad772f3706cbba3b0eea (diff) | |
download | astro-24663c9695385fed9ece57bf4aecdca3a8581e70.tar.gz astro-24663c9695385fed9ece57bf4aecdca3a8581e70.tar.zst astro-24663c9695385fed9ece57bf4aecdca3a8581e70.zip |
fix(rss): make title optional if description is provided (#9610)
* fix(rss): make title optional if description is provided
* feat(rss): simplify schema
* fix(rss): update tests to match new behavior
* Update packages/astro-rss/test/pagesGlobToRssItems.test.js
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
* Update packages/astro-rss/test/pagesGlobToRssItems.test.js
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
* feat: make link and pubDate optional
* feat: improve item normalization
* Update shy-spoons-sort.md
* Fix test fail
* Update .changeset/shy-spoons-sort.md
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
---------
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Diffstat (limited to 'packages/astro-rss/src/schema.ts')
-rw-r--r-- | packages/astro-rss/src/schema.ts | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/packages/astro-rss/src/schema.ts b/packages/astro-rss/src/schema.ts index 98aa35f81..788fe86fb 100644 --- a/packages/astro-rss/src/schema.ts +++ b/packages/astro-rss/src/schema.ts @@ -1,12 +1,11 @@ import { z } from 'astro/zod'; -export const rssSchema = z.object({ - title: z.string(), +const sharedSchema = z.object({ pubDate: z .union([z.string(), z.number(), z.date()]) - .transform((value) => new Date(value)) - .refine((value) => !isNaN(value.getTime())), - description: z.string().optional(), + .optional() + .transform((value) => (value === undefined ? value : new Date(value))) + .refine((value) => (value === undefined ? value : !isNaN(value.getTime()))), customData: z.string().optional(), categories: z.array(z.string()).optional(), author: z.string().optional(), @@ -19,4 +18,21 @@ export const rssSchema = z.object({ type: z.string(), }) .optional(), + link: z.string().optional(), + content: z.string().optional(), }); + +export const rssSchema = z.union([ + z + .object({ + title: z.string(), + description: z.string().optional(), + }) + .merge(sharedSchema), + z + .object({ + title: z.string().optional(), + description: z.string(), + }) + .merge(sharedSchema), +]); |