newsnow/server/sources/cankaoxiaoxi.ts

25 lines
681 B
TypeScript
Raw Normal View History

2024-10-09 02:53:38 +08:00
interface Res {
list: {
data: {
id: string
title: string
// 北京时间
url: string
publishTime: string
}
}[]
}
export default defineSource(async () => {
const res = await Promise.all(["zhongguo", "guandian", "gj"].map(k => $fetch(`https://china.cankaoxiaoxi.com/json/channel/${k}/list.json`) as Promise<Res>))
if (!res?.[0]?.list?.length) throw new Error("Cannot fetch data")
return res.map(k => k.list).flat().map(k => ({
id: k.data.id,
title: k.data.title,
extra: {
date: tranformToUTC(k.data.publishTime),
},
url: k.data.url,
2024-10-13 13:59:23 +08:00
})).sort((m, n) => m.extra.date < n.extra.date ? 1 : -1).slice(0, 30)
2024-10-09 02:53:38 +08:00
})