rss
This commit is contained in:
parent
18f90e6c4d
commit
300a6455a0
3 changed files with 26 additions and 23 deletions
|
@ -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)}
|
||||
/>
|
||||
|
||||
|
|
|
@ -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 };
|
|
@ -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}/`,
|
||||
})),
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue