🐛 fix rss bugs
This commit is contained in:
parent
c26c1da4ed
commit
d9dfec6dbc
2 changed files with 17 additions and 22 deletions
|
@ -1,16 +1,9 @@
|
||||||
import { defineCollection, z } from 'astro:content';
|
import { defineCollection, z } from 'astro:content';
|
||||||
|
import { rssSchema } from '@astrojs/rss';
|
||||||
|
|
||||||
const blog = defineCollection({
|
const blog = defineCollection({
|
||||||
// Type-check frontmatter using a schema
|
// Type-check frontmatter using a schema
|
||||||
schema: z.object({
|
schema: rssSchema
|
||||||
title: z.string(),
|
|
||||||
description: z.string(),
|
|
||||||
// Transform string to Date object
|
|
||||||
pubDate: z
|
|
||||||
.string()
|
|
||||||
.or(z.date())
|
|
||||||
.transform((val) => new Date(val))
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const collections = { blog };
|
export const collections = { blog };
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
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: 'Sindre Kjelsrud',
|
||||||
description: SITE_DESCRIPTION,
|
description: 'Recent content on Sindre Kjelsrud`s blog',
|
||||||
site: context.site,
|
site: context.site,
|
||||||
items: posts.map((post) => ({
|
items: blog.map((post) => ({
|
||||||
...post.data,
|
title: post.data.title,
|
||||||
link: `/blog/${post.slug}/`,
|
pubDate: post.data.pubDate,
|
||||||
})),
|
description: post.data.description,
|
||||||
});
|
customData: post.data.customData,
|
||||||
}
|
link: `/blog/${post.slug}/`,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue