Merge pull request #6660 from nczitzk/feature/zhihu

feat: add zhihu hotlist with categories
This commit is contained in:
NeverBehave 2021-01-10 23:46:48 -05:00 committed by GitHub
commit f6f3ca1c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View File

@ -1114,6 +1114,16 @@ rule
<Route author="DIYgod" example="/zhihu/hotlist" path="/zhihu/hotlist" anticrawler="1" radar="1" rssbud="1"/>
### 知乎分类热榜
<Route author="nczitzk" example="/zhihu/hot" path="/zhihu/hot/:category?" :paramsDesc="['分类,见下表,默认为全站']" anticrawler="1" radar="1" rssbud="1">
| 全站 | 国际 | 科学 | 汽车 | 视频 | 时尚 | 时事 | 数码 | 体育 | 校园 | 影视 |
| ----- | ----- | ------- | ---- | ------ | ------- | ----- | ------- | ----- | ------ | ---- |
| total | focus | science | car | zvideo | fashion | depth | digital | sport | school | film |
</Route>
### 知乎想法热榜
<Route author="xyqfer" example="/zhihu/pin/hotlist" path="/zhihu/pin/hotlist" anticrawler="1" radar="1" rssbud="1"/>

View File

@ -159,6 +159,7 @@ router.get('/zhihu/bookstore/newest', require('./routes/zhihu/bookstore/newest')
router.get('/zhihu/pin/daily', require('./routes/zhihu/pin/daily'));
router.get('/zhihu/weekly', require('./routes/zhihu/weekly'));
router.get('/zhihu/timeline', require('./routes/zhihu/timeline'));
router.get('/zhihu/hot/:category?', require('./routes/zhihu/hot'));
// 妹子图
router.get('/mzitu/home/:type?', require('./routes/mzitu/home'));

37
lib/routes/zhihu/hot.js Normal file
View File

@ -0,0 +1,37 @@
const got = require('@/utils/got');
const titles = {
total: '全站',
focus: '国际',
science: '科学',
car: '汽车',
zvideo: '视频',
fashion: '时尚',
depth: '时事',
digital: '数码',
sport: '体育',
school: '校园',
film: '影视',
};
module.exports = async (ctx) => {
const category = ctx.params.category || 'total';
const response = await got({
method: 'get',
url: `https://www.zhihu.com/api/v3/feed/topstory/hot-lists/${category}?limit=50`,
});
const items = response.data.data.map((item) => ({
link: item.target.url,
title: item.target.title,
pubDate: new Date(item.target.created * 1000).toUTCString(),
description: item.target.excerpt ? `<p>${item.target.excerpt}</p>` : '',
}));
ctx.state.data = {
title: `知乎热榜 - ${titles[category]}`,
link: `https://www.zhihu.com/hot?list=${category}`,
item: items,
};
};