From e6fb5a45192e1cacfa4acc99772dc136fcd04b95 Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Thu, 18 Jun 2026 15:45:32 +0800 Subject: [PATCH] Seperate zh-cn and en-us rss --- src/pages/[lang]/index.astro | 3 ++- src/pages/en/rss.xml.js | 35 +++++++++++++++++++++++++++++++++++ src/pages/rss.xml.js | 30 +++++++++++++++++++----------- 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 src/pages/en/rss.xml.js diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index 986e330..5a0b04c 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -14,13 +14,14 @@ const lang = getLangFromUrl(Astro.url); const t = getTranslations(lang); const headerTitle = lang === "zh" ? "Cloverta的博客" : "Cloverta's blog"; const pageTitle = t.home.title; +const rssLink = lang === "zh" ? "/rss.xml" : "/en/rss.xml" ---

{pageTitle} post.id.startsWith('en/')) + .sort( + (a, b) => + new Date(b.data.pubDate).getTime() - + new Date(a.data.pubDate).getTime() + ); + + return rss({ + title: "Cloverta's Blog", + description: + "Discover more here. Welcome to Cloverta's blog 🥳", + site: context.site, + + items: enPosts.map((post) => { + const [, ...slugParts] = post.id.split('/'); + const slug = slugParts.join('/'); + + return { + title: post.data.title, + pubDate: post.data.pubDate, + description: post.data.description, + link: `/en/posts/${slug}/`, + }; + }), + + customData: 'en-US', + }); +} \ No newline at end of file diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index a8fd191..9fbe52f 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,26 +1,34 @@ import rss from '@astrojs/rss'; -import { pagesGlobToRssItems } from '@astrojs/rss'; import { getCollection } from 'astro:content'; export async function GET(context) { - const posts = await getCollection("blog"); + const posts = await getCollection('blog'); + + const zhPosts = posts + .filter((post) => post.id.startsWith('zh/')) + .sort( + (a, b) => + new Date(b.data.pubDate).getTime() - + new Date(a.data.pubDate).getTime() + ); return rss({ title: 'Cloverta的博客', description: '在这里,发现更多(雾)欢迎来到三叶的博客🥳', site: context.site, - items: await pagesGlobToRssItems(import.meta.glob('./**/*.md')), - items: posts.map((post) => { - const [postLang, ...slugParts] = post.id.split("/"); - const slug = slugParts.join("/"); - return ({ + items: zhPosts.map((post) => { + const [, ...slugParts] = post.id.split('/'); + const slug = slugParts.join('/'); + + return { title: post.data.title, pubDate: post.data.pubDate, description: post.data.description, - link: `/${postLang}/posts/${slug}/`, - }) + link: `/zh/posts/${slug}/`, + }; }), - customData: `en-us`, - }) + + customData: 'zh-CN', + }); } \ No newline at end of file