Parin's Space
返回文章列表

新增 RSS Feed

· 閱讀時間 1 分鐘

部落格現在提供 RSS Feed,可以在 /rss.xml 取得。

什麼是 RSS?

RSS(Really Simple Syndication)是一種訂閱格式,讓你不需要主動回來查看網站,只要用 RSS 閱讀器訂閱,新文章發布時就會自動出現在你的閱讀清單。

常用的 RSS 閱讀器:

  • NetNewsWire — macOS / iOS,免費開源
  • Reeder — macOS / iOS,介面簡潔
  • Miniflux — 自架 web-based,輕量
  • Feedly — 跨平台,有免費方案

訂閱方式

把以下網址加進你的 RSS 閱讀器:

https://blog.parin.dev/rss.xml

技術實作

使用 @astrojs/rss 套件,在 src/pages/rss.xml.ts 產生 feed:

import rss from "@astrojs/rss";
import { getCollection } from "astro:content";

export async function GET(context) {
  const posts = await getCollection("blog", ({ data }) => data.published !== false);
  const sorted = posts.sort(
    (a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime()
  );

  return rss({
    title: "Parin's Blog",
    description: "技術筆記、工具折騰、日常觀察",
    site: context.site,
    items: sorted.map((post) => ({
      title: post.data.title,
      pubDate: new Date(post.data.date),
      description: post.data.summary,
      link: `/blog/${post.id}/`,
      categories: post.data.tags,
    })),
    customData: `<language>zh-TW</language>`,
  });
}

Feed 包含所有已發布文章的標題、摘要、發布日期與標籤,依日期降序排列。