mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-blog.git
synced 2026-07-03 15:41:26 +00:00
Compare commits
3 commits
1a05970cfb
...
7b222883c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b222883c2 | ||
|
|
f47501d79d | ||
| e6fb5a4519 |
3 changed files with 56 additions and 12 deletions
|
|
@ -14,13 +14,14 @@ const lang = getLangFromUrl(Astro.url);
|
||||||
const t = getTranslations(lang);
|
const t = getTranslations(lang);
|
||||||
const headerTitle = lang === "zh" ? "Cloverta的博客" : "Cloverta's blog";
|
const headerTitle = lang === "zh" ? "Cloverta的博客" : "Cloverta's blog";
|
||||||
const pageTitle = t.home.title;
|
const pageTitle = t.home.title;
|
||||||
|
const rssLink = lang === "zh" ? "/rss.xml" : "/en/rss.xml"
|
||||||
---
|
---
|
||||||
|
|
||||||
<BaseLayout pageTitle=`${headerTitle} - ${t.banner.subtitle}`>
|
<BaseLayout pageTitle=`${headerTitle} - ${t.banner.subtitle}`>
|
||||||
<h1 class="page-title">
|
<h1 class="page-title">
|
||||||
<span>{pageTitle}</span>
|
<span>{pageTitle}</span>
|
||||||
<a
|
<a
|
||||||
href={`/rss.xml`}
|
href={rssLink}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
aria-label="RSS Feed"
|
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 rss from '@astrojs/rss';
|
||||||
import { pagesGlobToRssItems } from '@astrojs/rss';
|
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
export async function GET(context) {
|
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({
|
return rss({
|
||||||
title: 'Cloverta的博客',
|
title: 'Cloverta的博客',
|
||||||
description: '在这里,发现更多(雾)欢迎来到三叶的博客🥳',
|
description: '在这里,发现更多(雾)欢迎来到三叶的博客🥳',
|
||||||
site: context.site,
|
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,
|
title: post.data.title,
|
||||||
pubDate: post.data.pubDate,
|
pubDate: post.data.pubDate,
|
||||||
description: post.data.description,
|
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