RSS 订阅
为你的文档/博客生成 RSS 订阅源。
安装
🌐 Setup
你可以创建 feed 对象:
🌐 You can create the feed object:
import { Feed } from 'feed';
import { source } from '@/lib/source';
const baseUrl = 'https://fumadocs.dev';
export function getRSS() {
const feed = new Feed({
title: 'Fumadocs Blog',
id: `${baseUrl}/blog`,
link: `${baseUrl}/blog`,
language: 'en',
image: `${baseUrl}/banner.png`,
favicon: `${baseUrl}/icon.png`,
copyright: 'All rights reserved 2025, Fuma Nama',
});
for (const page of source.getPages()) {
feed.addItem({
id: page.url,
title: page.data.title,
description: page.data.description,
link: `${baseUrl}${page.url}`,
date: new Date(page.data.lastModified),
author: [
{
name: 'Fuma',
},
],
});
}
return feed.rss2();
}并使用服务器加载器/路由处理器来暴露它,例如:
🌐 And expose it using a server loader/route handler like:
import { getRSS } from '@/lib/rss';
export const revalidate = false;
export function GET() {
return new Response(getRSS());
}Next.js 元数据
🌐 Next.js Metadata
你可以在元数据对象中添加一个 alternates 对象,其中包含你的 feed 的标题和 URL。
🌐 You can add an alternates object to the metadata object with your feed’s title and URL.
import type { Metadata } from 'next';
export const metadata: Metadata = {
alternates: {
types: {
'application/rss+xml': [
{
title: 'Fumadocs Blog',
url: 'https://fumadocs.dev/blog/index.xml',
},
],
},
},
};Last updated on
