RSS 源
为您的文档/博客生成 RSS 源。
设置
您可以创建源对象:
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();
}并使用服务器加载器/路由处理程序像这样暴露它:
import { getRSS } from '@/lib/rss';
export const revalidate = false;
export function GET() {
return new Response(getRSS());
}Next.js 元数据
您可以将交替对象添加到元数据对象中,其中包含源的标题和 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',
},
],
},
},
};How is this guide?
Last updated on
