feat(source): add baidu

close #13
This commit is contained in:
Ou 2024-10-27 23:32:50 +08:00
parent 655204a14f
commit 47767a6d62
4 changed files with 39 additions and 2 deletions

1
server/glob.d.ts vendored
View File

@ -2,6 +2,7 @@
declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const _36kr: typeof import('./sources/_36kr')
export const baidu: typeof import('./sources/baidu')
export const bilibili: typeof import('./sources/bilibili')
export const cankaoxiaoxi: typeof import('./sources/cankaoxiaoxi')
export const cls: typeof import('./sources/cls/index')

29
server/sources/baidu.ts Normal file
View File

@ -0,0 +1,29 @@
interface Res {
data: {
cards: {
content: {
isTop?: boolean
word: string
rawUrl: string
desc?: string
}[]
}[]
}
}
export default defineSource(async () => {
const rawData: string = await $fetch(`https://top.baidu.com/board?tab=realtime`)
const jsonStr = (rawData as string).match(/<!--s-data:(.*?)-->/s)
const data: Res = JSON.parse(jsonStr![1])
return data.data.cards[0].content.filter(k => !k.isTop).map((k) => {
return {
id: k.rawUrl,
title: k.word,
url: k.rawUrl,
extra: {
hover: k.desc,
},
}
})
})

View File

@ -42,7 +42,7 @@ export default defineSource(async () => {
// 获取热榜列表数据
const hotRankData = data.defaultClient[hotRankId] as HotRankData
// 转换数据格式
return hotRankData.items.map((item) => {
return hotRankData.items.filter(k => data.defaultClient[k.id].tagType !== "置顶").map((item) => {
// 从id中提取实际的热搜词
const hotSearchWord = item.id.replace("VisionHotRankItem:", "")

View File

@ -254,7 +254,7 @@ export const originSources = {
column: "china",
color: "orange",
// cloudflare pages cannot access
// disable: true,
disable: true,
home: "https://www.kuaishou.com",
},
"kaopu": {
@ -272,6 +272,13 @@ export const originSources = {
type: "realtime",
home: "https://www.jin10.com",
},
"baidu": {
name: "百度热搜",
column: "china",
color: "blue",
type: "hottest",
home: "https://www.baidu.com",
},
} as const satisfies Record<string, OriginSource>
export const sources = genSources()