This commit is contained in:
nelle 2024-06-26 17:59:04 -06:00
parent 18f90e6c4d
commit 300a6455a0
3 changed files with 26 additions and 23 deletions

View file

@ -17,4 +17,10 @@ const { title, description } = Astro.props;
<meta name="generator" content={Astro.generator} />
<link rel="stylesheet" href="/css/mystyle.css" />
<link rel="icon" type="image/svg+xml" href="/assets/favicon.svg" />
<link
rel="alternate"
type="application/rss+xml"
title="LimePot"
href={new URL("rss.xml", Astro.site)}
/>

View file

@ -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 };

View file

@ -1,15 +1,19 @@
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');
const blog = await getCollection('blog');
return rss({
title: SITE_TITLE,
description: SITE_DESCRIPTION,
site: context.site,
items: posts.map((post) => ({
...post.data,
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}/`,
})),
});