This commit is contained in:
@ -17,6 +17,12 @@ const { title = '小帕的小窝' } = Astro.props
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
title="小帕的小窝 RSS 订阅"
|
||||
href={new URL('rss.xml', Astro.site || 'https://passthem.top')}
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{title}</title>
|
||||
|
||||
@ -1,5 +1,20 @@
|
||||
import { legacyClient } from '../clients'
|
||||
|
||||
export type ListBlogItemType = {
|
||||
id: number
|
||||
title: string
|
||||
|
||||
/** ISO8601 */
|
||||
created_at: string
|
||||
|
||||
/** ISO8601 */
|
||||
updated_at: string
|
||||
|
||||
featured_image: null | {
|
||||
image_url: string
|
||||
}
|
||||
}
|
||||
|
||||
export const listBlogs = async ({
|
||||
page = 1,
|
||||
limit = 20,
|
||||
@ -8,13 +23,7 @@ export const listBlogs = async ({
|
||||
limit?: number
|
||||
}) => {
|
||||
const resp = await legacyClient.post('/v1/blog/list', { page, limit })
|
||||
return resp.data.data as {
|
||||
id: number
|
||||
title: string
|
||||
featured_image: null | {
|
||||
image_url: string
|
||||
}
|
||||
}[]
|
||||
return resp.data.data as ListBlogItemType[]
|
||||
}
|
||||
|
||||
export const getBlog: (
|
||||
|
||||
32
src/pages/rss.xml.ts
Normal file
32
src/pages/rss.xml.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import rss from '@astrojs/rss'
|
||||
import type { APIRoute } from 'astro'
|
||||
import { listBlogs, type ListBlogItemType } from '../lib/apis/legacy/blog'
|
||||
|
||||
export const GET = (async (context) => {
|
||||
let blogs: ListBlogItemType[] = []
|
||||
let pid = 0
|
||||
|
||||
let newBlogs = []
|
||||
|
||||
while (pid == 0 || newBlogs.length > 0) {
|
||||
newBlogs = await listBlogs({
|
||||
page: ++pid,
|
||||
limit: 100,
|
||||
})
|
||||
blogs = [...blogs, ...newBlogs]
|
||||
}
|
||||
|
||||
const site = context.site || 'https://passthem.top'
|
||||
|
||||
return rss({
|
||||
title: '小帕的小窝',
|
||||
description: '小帕和他朋友们的博客',
|
||||
site,
|
||||
items: blogs.map((blog) => ({
|
||||
title: blog.title,
|
||||
link: `${site}/blogs/${blog.id}`,
|
||||
pubDate: new Date(blog.created_at),
|
||||
})),
|
||||
customData: `<language>zh-hans</language>`,
|
||||
})
|
||||
}) satisfies APIRoute
|
||||
Reference in New Issue
Block a user