feat: add new rss

This commit is contained in:
KazooTTT
2024-11-25 21:47:51 +08:00
parent 94bf7ee820
commit 29650452a1
6 changed files with 37 additions and 32 deletions

View File

@ -1,28 +0,0 @@
import rss from '@astrojs/rss'
import { siteConfig } from '@/site-config'
import { getAllSortedPosts } from '@/utils'
export const GET = async () => {
const posts = await getAllSortedPosts()
const items = await Promise.all(
posts.map(async (post) => {
const entry = post
const body = entry.body
return {
title: post.data.title ?? '',
description: JSON.stringify(body),
pubDate: post.data.date,
link: `/blog/${post.slug}`
}
})
)
return rss({
title: siteConfig.title,
description: siteConfig.description + '\nfeedId:76245438397618182+userId:62156866798228480',
site: import.meta.env.SITE,
items
})
}

33
src/pages/rss.xml.ts Normal file
View File

@ -0,0 +1,33 @@
import { siteConfig } from '@/site-config'
import { getAllSortedPosts } from '@/utils'
import rss from '@astrojs/rss'
import type { APIContext } from 'astro'
export async function GET(context: APIContext) {
const blog = await getAllSortedPosts()
return rss({
// `<title>` field in output xml
title: siteConfig.title,
// `<description>` field in output xml
description: siteConfig.description,
// Pull in your project "site" from the endpoint context
// https://docs.astro.build/en/reference/api-reference/#contextsite
site: context.site!,
// Array of `<item>`s in output xml
// See "Generating items" section for examples using content collections and glob imports
items: blog.map((post) => ({
title: post.data.title,
pubDate: post.data.date,
description: post.data.description ?? '',
// Compute RSS link from post `slug`
// This example assumes all posts are rendered as `/blog/[slug]` routes
link: `/blog/${post.slug}/`
})),
// Add custom XML elements
customData: `
<follow_challenge>
<feedId>83074007039123456</feedId>
<userId>62156866798228480</userId>
</follow_challenge>`
})
}