fix: fix RSS build error

This commit is contained in:
saicaca 2024-09-04 23:13:58 +08:00
parent 4518dbf0f8
commit 1af707ee6a
2 changed files with 4 additions and 5 deletions

View File

@ -15,13 +15,12 @@ export async function GET(context: APIContext) {
description: siteConfig.subtitle || 'No description', description: siteConfig.subtitle || 'No description',
site: context.site ?? 'https://fuwari.vercel.app', site: context.site ?? 'https://fuwari.vercel.app',
items: blog.map(post => { items: blog.map(post => {
const body = typeof post.data.body === 'string' ? post.data.body : ''
return { return {
title: post.data.title, title: post.data.title,
pubDate: post.data.published, pubDate: post.data.published,
description: post.data.description || '', description: post.data.description || '',
link: `/posts/${post.slug}/`, link: `/posts/${post.slug}/`,
content: sanitizeHtml(parser.render(body), { content: sanitizeHtml(parser.render(post.body), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']), allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
}), }),
} }

View File

@ -4,14 +4,14 @@ import I18nKey from '@i18n/i18nKey'
import { i18n } from '@i18n/translation' import { i18n } from '@i18n/translation'
export async function getSortedPosts(): Promise< export async function getSortedPosts(): Promise<
{ data: BlogPostData; slug: string }[] { body: string, data: BlogPostData; slug: string }[]
> { > {
const allBlogPosts = (await getCollection('posts', ({ data }) => { const allBlogPosts = (await getCollection('posts', ({ data }) => {
return import.meta.env.PROD ? data.draft !== true : true 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( 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 dateA = new Date(a.data.published)
const dateB = new Date(b.data.published) const dateB = new Date(b.data.published)
return dateA > dateB ? -1 : 1 return dateA > dateB ? -1 : 1