Astro2.0のRSS

rss.xml.js の記述方法が変更
記事の取得方法が collection になったため以前の方法は利用できない
以下のようにするのが良いと Astro の github で見かけた
ファイル名も rss.xml.ts
とした
---import rss from "@astrojs/rss";import { getCollection } from "astro:content";import { BLOG_NAME, SITE_TITLE, SITE_DESCRIPTION } from "@config/config";
export const get = async () => { const posts = await getCollection(BLOG_NAME); return rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, site: import.meta.env.SITE, items: posts.map((post) => ({ title: post.data.title, description: post.data.description, pubDate: post.data.date, link: BLOG_NAME + "/" + post.slug, })), });};
RSS の link が正しくなくなる
上記の例では rss のプロパティ link: post.slug にパスを付け足している
post.slug だけでは正しい URL にならないため content フォルダ内でのフォルダ名を先頭につける必要がある
# そのままpost.slugだけだとこのようにURLが正しくなくなるhttps://ubanis.com/2023/2023-01-22/
# 先頭にcontentの中でのフォルダ名を付与する必要があるhttps://ubanis.com/blog/2023/2023-01-22/