ADNKDN

feedの追加

2024-02-18

このブログにfeedを追加。 https://adnkdn.eedama.me/feed.xml

結果としてほぼ↓の記事の通りとなった。
https://spacejelly.dev/posts/sitemaps-rss-feeds-with-next-js-app-router

APIとしてxmlを返す

Next.js App Routerでは、 app/[slug]/route.ts をAPIとして扱うっぽい。
https://nextjs.org/docs/app/building-your-application/routing/route-handlers
なので、 app/feed.xml/route.ts として書くことで、 /feed.xml へのリクエストをこのAPIで捌ける。

で、以下のようにResponseを返してあげればOK。なるほどなぁ

return new Response(feed.xml({ indent: true }), {
  headers: {
    'Content-Type': 'application/atom+xml; charset=utf-8',
  },
});

記事一覧