From 707dae5af1ba2618dff233ca564e43f528fbb3ba Mon Sep 17 00:00:00 2001 From: Ou Date: Tue, 8 Oct 2024 22:44:42 +0800 Subject: [PATCH] feat: source add zhihu --- server/sources/index.ts | 2 ++ server/sources/zhihu.ts | 38 ++++++++++++++++++++++++++++++++++++++ shared/data.ts | 4 ++-- shared/sources.ts | 4 +++- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 server/sources/zhihu.ts diff --git a/server/sources/index.ts b/server/sources/index.ts index c372d12..ad99904 100644 --- a/server/sources/index.ts +++ b/server/sources/index.ts @@ -3,6 +3,7 @@ import weibo from "./weibo" import zaobao from "./zaobao" import v2ex from "./v2ex" import ithome from "./ithome" +import zhihu from "./zhihu" export const sourcesFn = { weibo, @@ -12,6 +13,7 @@ export const sourcesFn = { "peopledaily": defineRSSSource("https://feedx.net/rss/people.xml", { hiddenDate: true, }), + "zhihu": zhihu, "sputniknewscn": defineRSSHubSource("/sputniknews/news/chinese"), "douyin": defineFallbackSource("douyin"), "aljazeeracn": defineRSSSource("https://feedx.net/rss/aljazeera.xml"), diff --git a/server/sources/zhihu.ts b/server/sources/zhihu.ts new file mode 100644 index 0000000..e2a8c85 --- /dev/null +++ b/server/sources/zhihu.ts @@ -0,0 +1,38 @@ +interface Res { + data: { + card_label?: { + icon: string + night_icon: string + } + target: { + id: number + title: string + url: string + created: number + answer_count: number + follower_count: number + bound_topic_ids: number[] + comment_count: number + is_following: boolean + excerpt: string + } + }[] +} + +export default defineSource(async () => { + const url = "https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=20&desktop=true" + const res: Res = await $fetch(url) + if (!res.data || res.data.length === 0) throw new Error("Cannot fetch data") + return res.data + .slice(0, 20) + .map((k) => { + return { + id: k.target.id, + title: k.target.title, + extra: { + icon: k.card_label?.night_icon, + }, + url: `https://www.zhihu.com/question/${k.target.id}`, + } + }) +}) diff --git a/shared/data.ts b/shared/data.ts index 9492596..552ecd0 100644 --- a/shared/data.ts +++ b/shared/data.ts @@ -9,11 +9,11 @@ export const metadata: Metadata = { }, social: { name: "实时", - sources: ["douyin", "weibo", "wallstreetcn", "ithome", "36kr"], + sources: ["weibo", "douyin", "zhihu", "toutiao", "wallstreetcn", "ithome", "36kr"], }, china: { name: "国内", - sources: ["peopledaily", "toutiao"], + sources: ["peopledaily", "toutiao", "zhihu"], }, world: { name: "国外", diff --git a/shared/sources.ts b/shared/sources.ts index 748fa53..c3c35e1 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -13,6 +13,7 @@ export const originSources = { }, "sputniknewscn": { name: "俄罗斯卫星通讯社", + interval: 30 * 60 * 1000, home: "https://sputniknews.cn", }, "aljazeeracn": { @@ -57,6 +58,7 @@ export const originSources = { }, "thepaper": { name: "澎湃新闻", + interval: 30 * 60 * 1000, home: "https://www.thepaper.cn", }, "toutiao": { @@ -65,11 +67,11 @@ export const originSources = { }, "cankaoxiaoxi": { name: "参考消息", + interval: 60 * 60 * 1000, home: "http://www.cankaoxiaoxi.com", }, "ithome": { name: "IT之家", - interval: 1000, home: "https://www.ithome.com", }, "peopledaily": {