diff --git a/src/lib/apis/legacy/blog.ts b/src/lib/apis/legacy/blog.ts index b484619..231383a 100644 --- a/src/lib/apis/legacy/blog.ts +++ b/src/lib/apis/legacy/blog.ts @@ -13,6 +13,12 @@ export type ListBlogItemType = { featured_image: null | { image_url: string } + + author: { + id: number + username: string + nickname: string + } } export const listBlogs = async ({ diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index 59223ca..aae61aa 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,6 +1,13 @@ -import rss from '@astrojs/rss' +import rss, { type RSSFeedItem } from '@astrojs/rss' import type { APIRoute } from 'astro' -import { listBlogs, type ListBlogItemType } from '../lib/apis/legacy/blog' +import { + getBlog, + listBlogs, + type ListBlogItemType, +} from '../lib/apis/legacy/blog' +import { ensureShikiEngine } from '../lib/markdown' +import { toMarkdocTree } from '../lib/markdoc' +import Markdoc from '@markdoc/markdoc' export const prerender = false @@ -19,16 +26,30 @@ export const GET = (async (context) => { } const site = context.site || 'https://passthem.top' + await ensureShikiEngine() return rss({ title: '小帕的小窝', description: '小帕和他朋友们的博客', site, - items: blogs.map((blog) => ({ - title: blog.title, - link: `${site}/blogs/${blog.id}`, - pubDate: new Date(blog.created_at), - })), + items: await Promise.all( + blogs.map(async (blog) => { + const blogContent = + (await getBlog(blog.id))?.content || '博客内容暂不可用' + const blogTree = await toMarkdocTree(blogContent) + const html = Markdoc.renderers.html(blogTree) + + const rssItem: RSSFeedItem = { + title: blog.title, + description: `一篇由 ${blog.author.nickname} 写的博客`, + link: `${site}/blogs/${blog.id}`, + pubDate: new Date(blog.created_at), + content: html, + } + + return rssItem + }), + ), customData: `zh-hans`, }) }) satisfies APIRoute