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

@ -23,7 +23,7 @@
"@astrojs/cloudflare": "^11.2.0",
"@astrojs/mdx": "^2.1.1",
"@astrojs/react": "^3.6.2",
"@astrojs/rss": "^4.0.5",
"@astrojs/rss": "^4.0.9",
"@astrojs/sitemap": "^3.1.1",
"@astrojs/tailwind": "^5.1.0",
"@giscus/react": "^3.0.0",

2
pnpm-lock.yaml generated
View File

@ -21,7 +21,7 @@ importers:
specifier: ^3.6.2
version: 3.6.3(@types/node@22.9.3)(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
'@astrojs/rss':
specifier: ^4.0.5
specifier: ^4.0.9
version: 4.0.9
'@astrojs/sitemap':
specifier: ^3.1.1

View File

@ -15,7 +15,7 @@ import { Image } from 'astro:assets'
class='mr-2 h-8 w-auto rounded-full sm:hidden'
loading='eager'
/>
<div class='hidden flex-none text-xl font-semibold sm:block' aria-label='Brand'>KazooTTT</div>
<div class='hidden flex-none text-xl font-semibold sm:block' aria-label='Brand'>声控烤箱</div>
</a>
<!-- Mobile menu button -->

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>`
})
}

View File

@ -5,7 +5,7 @@ export const siteConfig: SiteConfig = {
// Used as both a meta property (src/components/BaseHead.astro L:31 + L:49) & the generated satori png (src/pages/og-image/[slug].png.ts)
author: 'KazooTTT',
// Meta property used to construct the meta title property, found in src/components/BaseHead.astro L:11
title: 'KazooTTT Blog',
title: '声控烤箱的博客|KazooTTT Blog',
// Meta property used as the default description meta property
description: '声控烤箱 我喜欢的烤箱是声控的 前端小透明',
// HTML lang property, found in src/layouts/Base.astro L:18