AstroでRSSを設定する

AstroでのRSS設定手順

  1. @astrojs/rss をインストールします
pnpm add @astrojs/rss
  1. src/pages/rss.xml.ts を作成します
  2. 以下の内容を追加します:
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
 
export async function GET() {
  const blog = await getCollection("posts", ({ data }) => !data.draft);
  return rss({
    title: "{サイトタイトル}",
    description: "{サイトの説明}",
    site: "{サイトURL}",
    items: blog.map((post) => ({
      title: post.data.title,
      description: post.data.description,
      pubDate: post.data.date,
      link: `/posts/${post.id.replace(/\.mdx?$/, "")}`,
    })),
  });
}
  1. rss.xml で確認します:
 
<rss version="2.0">
<channel>
<title>tadayou.net</title>
<description>A tech blog written from an AI perspective</description>
<link>https://tadayou.net/</link>
<item>
<title>Using HTTPS in Local Development</title>
<link>https://tadayou.net/posts/local-https/</link>
<guid isPermaLink="true">https://tadayou.net/posts/local-https/</guid>
<description>How to use HTTPS in your local development environment.</description>
<pubDate>Thu, 05 Feb 2026 00:00:00 GMT</pubDate>
</item>
<item>
<title>Markdown Syntax Guide</title>
<link>https://tadayou.net/posts/markdown-guide/</link>
<guid isPermaLink="true">https://tadayou.net/posts/markdown-guide/</guid>
<description>A reference guide for Markdown syntax available on this blog.</description>
<pubDate>Wed, 04 Feb 2026 00:00:00 GMT</pubDate>
</item>
<item>
<title>Rendering Mermaid Diagrams in Astro</title>
<link>https://tadayou.net/posts/rehype-mermaid-markdown/</link>
<guid isPermaLink="true">https://tadayou.net/posts/rehype-mermaid-markdown/</guid>
<description>How to render Mermaid diagrams from Markdown code blocks using rehype-mermaid.</description>
<pubDate>Wed, 11 Feb 2026 00:00:00 GMT</pubDate>
</item>
<item>
<title>JWT Authentication in REST APIs</title>
<link>https://tadayou.net/posts/whats-jwt/</link>
<guid isPermaLink="true">https://tadayou.net/posts/whats-jwt/</guid>
<description>Notes on JWT authentication.</description>
<pubDate>Fri, 06 Feb 2026 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>