From 1af707ee6a9fa6d70684eb6df3c8d4055532d959 Mon Sep 17 00:00:00 2001 From: saicaca Date: Wed, 4 Sep 2024 23:13:58 +0800 Subject: [PATCH] fix: fix RSS build error --- src/pages/rss.xml.ts | 3 +-- src/utils/content-utils.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index b7a080f..2b733f4 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -15,13 +15,12 @@ export async function GET(context: APIContext) { description: siteConfig.subtitle || 'No description', site: context.site ?? 'https://fuwari.vercel.app', items: blog.map(post => { - const body = typeof post.data.body === 'string' ? post.data.body : '' return { title: post.data.title, pubDate: post.data.published, description: post.data.description || '', link: `/posts/${post.slug}/`, - content: sanitizeHtml(parser.render(body), { + content: sanitizeHtml(parser.render(post.body), { allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']), }), } diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index 6e670cc..d1ee224 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -4,14 +4,14 @@ import I18nKey from '@i18n/i18nKey' import { i18n } from '@i18n/translation' export async function getSortedPosts(): Promise< - { data: BlogPostData; slug: string }[] + { body: string, data: BlogPostData; slug: string }[] > { const allBlogPosts = (await getCollection('posts', ({ data }) => { return import.meta.env.PROD ? data.draft !== true : true - })) as unknown as { data: BlogPostData; slug: string }[] + })) as unknown as { body: string, data: BlogPostData; slug: string }[] const sorted = allBlogPosts.sort( - (a: { data: { published: Date } }, b: { data: { published: Date } }) => { + (a: { data: BlogPostData }, b: { data: BlogPostData }) => { const dateA = new Date(a.data.published) const dateB = new Date(b.data.published) return dateA > dateB ? -1 : 1