mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-blog.git
synced 2026-07-03 15:41:26 +00:00
Merge branch 'blog-content' of https://github.com/ClovertaTheTrilobita/SanYeCao-blog into blog-content
This commit is contained in:
commit
8d1e8fa0cb
3 changed files with 56 additions and 12 deletions
|
|
@ -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"
|
||||
---
|
||||
|
||||
<BaseLayout pageTitle=`${headerTitle} - ${t.banner.subtitle}`>
|
||||
<h1 class="page-title">
|
||||
<span>{pageTitle}</span>
|
||||
<a
|
||||
href={`/rss.xml`}
|
||||
href={rssLink}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label="RSS Feed"
|
||||
|
|
|
|||
35
src/pages/en/rss.xml.js
Normal file
35
src/pages/en/rss.xml.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import rss from '@astrojs/rss';
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
export async function GET(context) {
|
||||
const posts = await getCollection('blog');
|
||||
|
||||
const enPosts = posts
|
||||
.filter((post) => 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: '<language>en-US</language>',
|
||||
});
|
||||
}
|
||||
|
|
@ -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: `<language>en-us</language>`,
|
||||
})
|
||||
|
||||
customData: '<language>zh-CN</language>',
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue