🐛 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 { rssSchema } from '@astrojs/rss'; | ||||
| 
 | ||||
| const blog = defineCollection({ | ||||
| 	// Type-check frontmatter using a schema
 | ||||
| 	schema: z.object({ | ||||
| 		title: z.string(), | ||||
| 		description: z.string(), | ||||
| 		// Transform string to Date object
 | ||||
| 		pubDate: z | ||||
| 			.string() | ||||
| 			.or(z.date()) | ||||
| 			.transform((val) => new Date(val)) | ||||
| 	}), | ||||
| 	schema: rssSchema | ||||
| }); | ||||
| 
 | ||||
| export const collections = { blog }; | ||||
|  |  | |||
|  | @ -1,16 +1,18 @@ | |||
| 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}/`, | ||||
| 		})), | ||||
| 	}); | ||||
| } | ||||
| export async function GET(context) { | ||||
|   const blog = await getCollection('blog'); | ||||
|   return rss({ | ||||
|     title: 'Sindre Kjelsrud', | ||||
|     description: 'Recent content on Sindre Kjelsrud`s blog', | ||||
|     site: context.site, | ||||
|     items: blog.map((post) => ({ | ||||
|       title: post.data.title, | ||||
|       pubDate: post.data.pubDate, | ||||
|       description: post.data.description, | ||||
|       customData: post.data.customData, | ||||
|       link: `/blog/${post.slug}/`, | ||||
|     })), | ||||
|   }); | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sindre Kjelsrud
						Sindre Kjelsrud