This commit is contained in:
@ -13,6 +13,12 @@ export type ListBlogItemType = {
|
|||||||
featured_image: null | {
|
featured_image: null | {
|
||||||
image_url: string
|
image_url: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
author: {
|
||||||
|
id: number
|
||||||
|
username: string
|
||||||
|
nickname: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const listBlogs = async ({
|
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 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
|
export const prerender = false
|
||||||
|
|
||||||
@ -19,16 +26,30 @@ export const GET = (async (context) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const site = context.site || 'https://passthem.top'
|
const site = context.site || 'https://passthem.top'
|
||||||
|
await ensureShikiEngine()
|
||||||
|
|
||||||
return rss({
|
return rss({
|
||||||
title: '小帕的小窝',
|
title: '小帕的小窝',
|
||||||
description: '小帕和他朋友们的博客',
|
description: '小帕和他朋友们的博客',
|
||||||
site,
|
site,
|
||||||
items: blogs.map((blog) => ({
|
items: await Promise.all(
|
||||||
title: blog.title,
|
blogs.map(async (blog) => {
|
||||||
link: `${site}/blogs/${blog.id}`,
|
const blogContent =
|
||||||
pubDate: new Date(blog.created_at),
|
(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>`,
|
customData: `<language>zh-hans</language>`,
|
||||||
})
|
})
|
||||||
}) satisfies APIRoute
|
}) satisfies APIRoute
|
||||||
|
|||||||
Reference in New Issue
Block a user