From 47767a6d6264803535bd897a6ef36dff60bd3e47 Mon Sep 17 00:00:00 2001 From: Ou Date: Sun, 27 Oct 2024 23:32:50 +0800 Subject: [PATCH] feat(source): add baidu close #13 --- server/glob.d.ts | 1 + server/sources/baidu.ts | 29 +++++++++++++++++++++++++++++ server/sources/kuaishou.ts | 2 +- shared/sources.ts | 9 ++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 server/sources/baidu.ts diff --git a/server/glob.d.ts b/server/glob.d.ts index 56748f9..9ccdbb2 100644 --- a/server/glob.d.ts +++ b/server/glob.d.ts @@ -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') diff --git a/server/sources/baidu.ts b/server/sources/baidu.ts new file mode 100644 index 0000000..c26d1c1 --- /dev/null +++ b/server/sources/baidu.ts @@ -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) + 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, + }, + } + }) +}) diff --git a/server/sources/kuaishou.ts b/server/sources/kuaishou.ts index 558c8e3..4eb447a 100644 --- a/server/sources/kuaishou.ts +++ b/server/sources/kuaishou.ts @@ -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:", "") diff --git a/shared/sources.ts b/shared/sources.ts index 9ee62f1..98fe9f0 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -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 export const sources = genSources()