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: page.data.lastModified ?? new Date(),
author: [
{
name: 'Fuma',
},
],
});
}
return feed.rss2();
}次に、ルートから配信します。
import { getRSS } from '@/lib/rss';
export function GET() {
return new Response(getRSS());
}
export async function getConfig() {
return {
render: 'static' as const,
} as const;
}フィードをリンクする
フィードリーダーがフィードを検出できるように、各ページからリンクしておきます。
// React が `<head>` 内に巻き上げます
<link rel="alternate" type="application/rss+xml" title="Fumadocs Blog" href="/rss.xml" />How is this guide?
最終更新日
