feat: enhance internationalization support with dynamic routing

This commit is contained in:
radishzzz 2025-01-18 02:25:00 +00:00
parent d6c98880d3
commit 8c19d26cfd
12 changed files with 199 additions and 87 deletions

View file

@ -24,11 +24,13 @@ function getExcerpt(content: string): string {
return `${plainText.slice(0, 100).trim()}...`
}
// Generate RSS feed
export async function GET(_context: APIContext) {
// Generate RSS feed for default language
export async function GET() {
// Only handle posts for default language
const posts = await getCollection(
'posts',
({ data }: { data: CollectionEntry<'posts'>['data'] }) => !data.draft,
({ data }: { data: CollectionEntry<'posts'>['data'] }) =>
(!data.draft && (data.lang === locale || data.lang === '')),
)
return rss({
@ -36,6 +38,7 @@ export async function GET(_context: APIContext) {
description,
site: url,
stylesheet: '/rss/styles.xsl',
// Map posts to RSS items
items: posts.map((post: CollectionEntry<'posts'>) => ({
title: post.data.title,
pubDate: post.data.published,
@ -48,13 +51,14 @@ export async function GET(_context: APIContext) {
},
),
})),
// Add language and follow challenge info
customData: `
<language>${locale}</language>
${followConfig?.feedID && followConfig?.userID
? `<follow_challenge>
<feedId>${followConfig.feedID}</feedId>
<userId>${followConfig.userID}</userId>
</follow_challenge>`
<feedId>${followConfig.feedID}</feedId>
<userId>${followConfig.userID}</userId>
</follow_challenge>`
: ''
}
`.trim(),