EveSunMaple / Frosti

A clean, elegant, and fast static blog template! 🚀 Developed with Astro
https://frosti.saroprock.com
GNU General Public License v3.0
198 stars 31 forks source link

Add RSS Full Text #52

Open yaotutu opened 3 days ago

yaotutu commented 3 days ago
//  /src/pages/rxx.xml.js
export async function GET(context) {
  const posts = await getCollection("blog");
  const siteUrl = context.site;
  return rss({
    title: SITE_TITLE,
    description: SITE_DESCRIPTION,
    site: siteUrl,
    items: posts.map((post) => {
      const { body } = post;

      // 使用 marked 解析 Markdown 内容,并调整图片路径
      const content = marked(body).replace(/src="([^"]+)"/g, (match, src) => {
        // 如果路径是相对路径,转换为绝对路径
        if (!src.startsWith("http") && !src.startsWith("//")) {
          return `src="${new URL(src, siteUrl).toString()}"`;
        }
        return match;
      });

      return {
        ...post.data,
        link: `/blog/${post.slug}/`,
        content, // 替换后的内容
      };
    }),
  });
}
EveSunMaple commented 2 days ago

Got it, I’ll handle this after fixing the existing issues in the project tonight.