This commit is contained in:
@ -13,6 +13,12 @@ export type ListBlogItemType = {
|
||||
featured_image: null | {
|
||||
image_url: string
|
||||
}
|
||||
|
||||
author: {
|
||||
id: number
|
||||
username: string
|
||||
nickname: string
|
||||
}
|
||||
}
|
||||
|
||||
export const listBlogs = async ({
|
||||
|
||||
@ -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: `<language>zh-hans</language>`,
|
||||
})
|
||||
}) satisfies APIRoute
|
||||
|
||||
Reference in New Issue
Block a user