refactor: optimize rss generation logic

This commit is contained in:
radishzzz 2025-03-17 14:01:51 +00:00
parent f34b0cb46b
commit 0888b59c5f
7 changed files with 128 additions and 155 deletions

View file

@ -2,7 +2,6 @@ import type { APIContext } from 'astro'
import { moreLocales } from '@/config'
import { generateRSS } from '@/utils/rss'
// Generate static paths for all supported languages
export function getStaticPaths() {
return moreLocales.map(lang => ({
params: { lang },
@ -11,14 +10,5 @@ export function getStaticPaths() {
export async function GET({ params }: APIContext) {
const lang = params.lang as typeof moreLocales[number]
// Return 404 if language is not supported
if (!moreLocales.includes(lang)) {
return new Response(null, {
status: 404,
statusText: 'Not found',
})
}
return generateRSS({ lang })
}

View file

@ -2,7 +2,6 @@ import type { APIContext } from 'astro'
import { moreLocales } from '@/config'
import { generateRSS } from '@/utils/rss'
// Generate static paths for all supported languages
export function getStaticPaths() {
return moreLocales.map(lang => ({
params: { lang },
@ -11,14 +10,5 @@ export function getStaticPaths() {
export async function GET({ params }: APIContext) {
const lang = params.lang as typeof moreLocales[number]
// Return 404 if language is not supported
if (!moreLocales.includes(lang)) {
return new Response(null, {
status: 404,
statusText: 'Not found',
})
}
return generateRSS({ lang })
}

View file

@ -6,7 +6,7 @@ import { getCollection } from 'astro:content'
// eslint-disable-next-line antfu/no-top-level-await
const blogEntries = await getCollection('posts')
// Convert to page data objects
// Convert blog entries into a lookup object with slug as key and title/description as value
const pages = Object.fromEntries(
blogEntries.map((post: CollectionEntry<'posts'>) => [
post.slug,