mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
refactor: optimize rss generation logic
This commit is contained in:
parent
f34b0cb46b
commit
0888b59c5f
7 changed files with 128 additions and 155 deletions
|
@ -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 })
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue