Commit b395f91

HPCesia <me@hpcesia.com>
2025-01-30 05:24:37
feat: add RSS feed
1 parent bfa5082
Changed files (3)
src/pages/rss.xml.ts
@@ -0,0 +1,19 @@
+import { siteConfig } from '@/config';
+import rss from '@astrojs/rss';
+import { getSortedPosts } from '@utils/content-utils';
+import type { AstroGlobal } from 'astro';
+
+export async function GET(context: AstroGlobal) {
+  const posts = await getSortedPosts();
+  return rss({
+    title: siteConfig.title,
+    description: siteConfig.subtitle,
+    site: context.site || '',
+    items: posts.map((post) => ({
+      title: post.data.title,
+      pubDate: post.data.published,
+      description: post.data.description,
+      link: `/posts/${post.data.abbrlink}`,
+    })),
+  });
+}
src/config.ts
@@ -49,7 +49,7 @@ export const navbarConfig: NavbarConfig = {
       {
         icon: 'material-symbols:rss-feed-rounded',
         text: I18nKey.subscribe,
-        onclick: '',
+        href: '/rss.xml',
       },
     ],
     always: [
package.json
@@ -11,6 +11,7 @@
     "format": "prettier --write ./src"
   },
   "dependencies": {
+    "@astrojs/rss": "^4.0.11",
     "@astrojs/sitemap": "^3.2.1",
     "@astrojs/tailwind": "^5.1.5",
     "@iconify-json/material-symbols": "^1.2.13",