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} />
|
<meta name="generator" content={Astro.generator} />
|
||||||
<link rel="stylesheet" href="/css/mystyle.css" />
|
<link rel="stylesheet" href="/css/mystyle.css" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/assets/favicon.svg" />
|
<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({
|
const blog = defineCollection({
|
||||||
type: 'content',
|
schema: rssSchema,
|
||||||
// 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(),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const collections = { blog };
|
export const collections = { blog };
|
|
@ -1,15 +1,19 @@
|
||||||
import rss from '@astrojs/rss';
|
import rss from '@astrojs/rss';
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
|
|
||||||
|
|
||||||
export async function GET(context) {
|
export async function GET(context) {
|
||||||
const posts = await getCollection('blog');
|
const blog = await getCollection('blog');
|
||||||
return rss({
|
return rss({
|
||||||
title: SITE_TITLE,
|
title: SITE_TITLE,
|
||||||
description: SITE_DESCRIPTION,
|
description: SITE_DESCRIPTION,
|
||||||
site: context.site,
|
site: context.site,
|
||||||
items: posts.map((post) => ({
|
items: blog.map((post) => ({
|
||||||
...post.data,
|
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}/`,
|
link: `/blog/${post.slug}/`,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue