TL;DR
RSS 允许读者订阅博客,之后有新文章时自动推送到阅读器,不需要每次手动访问网站。给 Astro 博客加 RSS 只需两步。
为什么还要用 RSS
社交媒体信息流靠算法分发,读者看到什么由平台决定。RSS 把主动权还给读者—订阅一次,有新内容就出现。
对于写博客人来说,RSS 订阅者是真正固定读者,不是靠算法偶然刷到流量。读者的 RSS 阅读器就是你专属推送通道。
常用 RSS 阅读器:Reeder(macOS/iOS)、NetNewsWire(免费)、Inoreader(跨平台)。
RSS 的工作原理
博客提供一个 XML 文件(rss.xml),包含所有文章最新列表和摘要。RSS 阅读器定期访问这个文件,发现新文章就推送给读者。
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>云图札记</title>
<link>https://blog.example.com</link>
<description>一个个人技术博客</description>
<item>
<title>从零搭建 Astro 博客</title>
<link>https://blog.example.com/blog/astro-from-scratch</link>
<pubDate>2026-06-11</pubDate>
<description>用 Astro 框架搭建博客,部署到 Cloudflare Pages……</description>
</item>
</channel>
</rss>
安装 Astro RSS
npm install @astrojs/rss
创建 RSS 源文件
在 src/pages/ 下新建 rss.xml.js:
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
export async function GET(context) {
const posts = await getCollection('blog');
return rss({
title: '云图札记',
description: '公爵的技术博客,专注 Astro 建站、开发工具与个人效率。',
site: context.site,
items: posts.map((post) => ({
title: post.data.title,
pubDate: post.data.pubDate,
description: post.data.description,
link: `/blog/${post.slug}/`,
})),
customData: `<language>zh-cn</language>`,
});
}
构建后在 rss.xml 访问 RSS 源。
在页面添加订阅链接
在 Header 或 Footer 的导航里加一个订阅图标:
<a href="/rss.xml" aria-label="RSS 订阅" target="_blank">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path d="M6.18 15.64a2.18 2.18 0 0 1 2.18 2.18C8.36 19.01 7.38 20 6.18 20C4.98 20 4 19.01 4 17.82a2.18 2.18 0 0 1 2.18-2.18M4 4.44A15.56 15.56 0 0 1 19.56 20h-2.83A12.73 12.73 0 0 0 4 7.27V4.44m0 5.66a9.9 9.9 0 0 1 9.9 9.9h-2.83A7.07 7.07 0 0 0 4 12.93V10.1z"/>
</svg>
</a>
用户点击后,RSS 阅读器会提示添加订阅。
验证 RSS 源是否正常
在终端用 curl 检查:
curl https://blog.example.com/rss.xml | head -20
或者用在线验证工具:Feed Validator
Atom 和 JSON Feed(可选)
如果想让订阅体验更现代,可以同时输出 Atom 或 JSON Feed 格式:
// src/pages/feed.json.js
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
export async function GET(context) {
const posts = await getCollection('blog');
return rss({
title: '云图札记',
site: context.site,
items: posts.map((post) => ({
title: post.data.title,
pubDate: post.data.pubDate,
description: post.data.description,
link: `/blog/${post.slug}/`,
})),
customData: `<language>zh-cn</language>`,
});
}
写在
RSS 是互联网早期开放协议,不依赖任何平台,不会算法限流。读者用 RSS 订阅你,是对内容质量认可。
给博客加上 RSS 只需要 10 分钟,但能让读者长期留住。
延伸阅读
COMMENTS
种下你的想法
在花园里留下一条评论,和这篇文章一起生长。