diff --git a/src/components/astro/header.astro b/src/components/astro/header.astro index bd8ee72..84caf75 100644 --- a/src/components/astro/header.astro +++ b/src/components/astro/header.astro @@ -10,14 +10,19 @@ const config = lang === "zh" ? zh : en ---
- +
{config.siteName}
{ config.rss && ( - + ) diff --git a/src/pages/[lang]/rss.xml.ts b/src/pages/[lang]/rss.xml.ts new file mode 100644 index 0000000..5bdd1ef --- /dev/null +++ b/src/pages/[lang]/rss.xml.ts @@ -0,0 +1,34 @@ +import rss from "@astrojs/rss" +import { en, zh } from "~/config" +import { getPostsByLocale } from "~/utils" +import { getLanguagePaths } from "~/utils/langs" + +export function getStaticPaths() { + return getLanguagePaths() +} + +export async function GET(request: { url: URL }) { + const isEn = request.url.pathname.includes("en") + + const lang = isEn ? "en" : "zh" + const config = isEn ? en : zh + + const posts = await getPostsByLocale(lang) + + return rss({ + title: config.meta.title, + description: config.meta.description, + site: + process.env.NODE_ENV === "development" + ? "http://localhost:4321" + : config.meta.url, + items: posts.map((post: any) => ({ + title: post.data.title, + description: post.data.description, + pubDate: post.data.pubDate, + link: `/posts/${post.id}/`, + content: post.rendered ? post.rendered.html : post.data.description, + })), + customData: "", + }) +} diff --git a/src/pages/atom/index.xml.ts b/src/pages/rss.xml.ts similarity index 79% rename from src/pages/atom/index.xml.ts rename to src/pages/rss.xml.ts index 142aa73..fe9e3e7 100644 --- a/src/pages/atom/index.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,9 +1,10 @@ import rss from "@astrojs/rss" -import { zh as config } from "~/config" +import { defaultLanguage, en, zh } from "~/config" import { getPostsByLocale } from "~/utils" export async function GET() { - const posts = await getPostsByLocale("zh") + const posts = await getPostsByLocale(defaultLanguage) + const config = defaultLanguage === "en" ? en : zh return rss({ title: config.meta.title,