From beaf75d4e5dd5d50995d720e0609d89ac8e61ff1 Mon Sep 17 00:00:00 2001 From: Andie Date: Sat, 1 Sep 2018 23:45:09 +0800 Subject: [PATCH] Zhihu hot list support (#616) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mentioned at https://github.com/DIYgod/RSSHub/issues/17#issuecomment-417828181 最后实际采用了上述issue中提到的第一个API 即 https://www.zhihu.com/api/v3/explore/guest/feeds?limit=15 虽然从路径上看,后两个更加语义化,但是只有第一个提供了全文 --- docs/README.md | 6 ++++++ router.js | 1 + routes/zhihu/hotlist.js | 42 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 routes/zhihu/hotlist.js diff --git a/docs/README.md b/docs/README.md index 9c34b61ce..4e5b75599 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1676,6 +1676,12 @@ GitHub 官方也提供了一些 RSS: 路由: `/zhihu/daily` +### 知乎热榜 + +举例: [https://rsshub.app/zhihu/hotlist](https://rsshub.app/zhihu/hotlist) + +路由: `/zhihu/hotlist` + ## 自如 ### 房源 diff --git a/router.js b/router.js index 6e6b965ea..e5d1aa642 100755 --- a/router.js +++ b/router.js @@ -156,6 +156,7 @@ router.get('/zhihu/people/activities/:id', require('./routes/zhihu/activities')) router.get('/zhihu/people/answers/:id', require('./routes/zhihu/answers')); router.get('/zhihu/zhuanlan/:id', require('./routes/zhihu/zhuanlan')); router.get('/zhihu/daily', require('./routes/zhihu/daily')); +router.get('/zhihu/hotlist', require('./routes/zhihu/hotlist')); // 妹子图 router.get('/mzitu', require('./routes/mzitu/category')); diff --git a/routes/zhihu/hotlist.js b/routes/zhihu/hotlist.js new file mode 100644 index 000000000..8017572d3 --- /dev/null +++ b/routes/zhihu/hotlist.js @@ -0,0 +1,42 @@ +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + console.log('run'); + const { + data: { data }, + } = await axios({ + method: 'get', + url: 'https://www.zhihu.com/api/v3/explore/guest/feeds?limit=40', + }); + + ctx.state.data = { + title: '知乎热榜', + link: 'https://www.zhihu.com/billboard', + description: '知乎热榜', + item: data.map((item) => { + switch (item.target.type) { + case 'answer': + return { + title: item.target.question.title, + description: `${item.target.author.name}的回答

${item.target.content}`, + pubDate: new Date(item.created_time).toUTCString(), + link: `https://www.zhihu.com/question/${item.target.question.id}`, + }; + case 'article': + return { + title: item.target.title, + description: `${item.target.author.name}的文章

${item.target.content}`, + pubDate: new Date(item.created_time).toUTCString(), + link: `https://zhuanlan.zhihu.com/p/${item.target.id}`, + }; + default: + return { + title: '未知类型', + description: '请点击链接提交issue', + pubDate: new Date(item.created_time).toUTCString(), + link: 'https://github.com/DIYgod/RSSHub/issues', + }; + } + }), + }; +};