From 300a6455a063b7b6351c4aeac2ee3a1526ace5e1 Mon Sep 17 00:00:00 2001 From: limepotato Date: Wed, 26 Jun 2024 17:59:04 -0600 Subject: [PATCH] rss --- src/components/Head.astro | 6 ++++++ src/content/config.ts | 15 ++++----------- src/pages/rss.xml.js | 28 ++++++++++++++++------------ 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/components/Head.astro b/src/components/Head.astro index 716acef..d2e3308 100755 --- a/src/components/Head.astro +++ b/src/components/Head.astro @@ -17,4 +17,10 @@ const { title, description } = Astro.props; + diff --git a/src/content/config.ts b/src/content/config.ts index bb4d8a1..0df5850 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,15 +1,8 @@ -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { rssSchema } from '@astrojs/rss'; const blog = defineCollection({ - type: 'content', - // Type-check frontmatter using a schema - schema: z.object({ - title: z.string(), - description: z.string(), - // Transform string to Date object - pubDate: z.coerce.date(), - updatedDate: z.coerce.date().optional(), - }), + schema: rssSchema, }); -export const collections = { blog }; +export const collections = { blog }; \ No newline at end of file diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 9ff9801..b30a634 100755 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,16 +1,20 @@ import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; -import { SITE_TITLE, SITE_DESCRIPTION } from '../consts'; export async function GET(context) { - const posts = await getCollection('blog'); - return rss({ - title: SITE_TITLE, - description: SITE_DESCRIPTION, - site: context.site, - items: posts.map((post) => ({ - ...post.data, - link: `/blog/${post.slug}/`, - })), - }); -} + const blog = await getCollection('blog'); + return rss({ + title: SITE_TITLE, + description: SITE_DESCRIPTION, + site: context.site, + items: blog.map((post) => ({ + title: post.data.title, + pubDate: post.data.pubDate, + description: post.data.description, + customData: post.data.customData, + // Compute RSS link from post `slug` + // This example assumes all posts are rendered as `/blog/[slug]` routes + link: `/blog/${post.slug}/`, + })), + }); +} \ No newline at end of file