feat: 掘金沸点按分类提供 RSS #3652 (#6197)

This commit is contained in:
Laam Pui
2020-11-24 11:58:01 +00:00
committed by GitHub
parent 4e47e74691
commit 3451909dee
3 changed files with 35 additions and 6 deletions
+7 -1
View File
@@ -472,7 +472,13 @@ GitHub 官方也提供了一些 RSS:
### 沸点
<Route author="xyqfer" example="/juejin/pins" path="/juejin/pins"/>
<Route author="xyqfer laampui" example="/juejin/pins/6824710202487472141" :paramsDesc="['默认为 recommend,见下表']" path="/juejin/pins/:type?">
| 推荐 | 热门 | 上班摸鱼 | 内推招聘 | 一图胜千言 | 今天学到了 | 每天一道算法题 | 开发工具推荐 | 树洞一下 |
| --------- | ---- | ------ | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| recommend | hot | 6824710203301167112 | 6819970850532360206 | 6824710202487472141 | 6824710202562969614 | 6824710202378436621 | 6824710202000932877 | 6824710203112423437 |
</Route>
### 专栏
+1 -1
View File
@@ -126,7 +126,7 @@ router.get('/juejin/category/:category', require('./routes/juejin/category'));
router.get('/juejin/tag/:tag', require('./routes/juejin/tag'));
router.get('/juejin/trending/:category/:type', require('./routes/juejin/trending'));
router.get('/juejin/books', require('./routes/juejin/books'));
router.get('/juejin/pins', require('./routes/juejin/pins'));
router.get('/juejin/pins/:type?', require('./routes/juejin/pins'));
router.get('/juejin/posts/:id', require('./routes/juejin/posts'));
router.get('/juejin/collections/:userId', require('./routes/juejin/favorites'));
router.get('/juejin/collection/:collectionId', require('./routes/juejin/collection'));
+27 -4
View File
@@ -1,17 +1,40 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const type = ctx.params.type || 'recommend';
const title = {
recommend: '推荐',
hot: '热门',
'6824710203301167112': '上班摸鱼',
'6819970850532360206': '内推招聘',
'6824710202487472141': '一图胜千言',
'6824710202562969614': '今天学到了',
'6824710202378436621': '每天一道算法题',
'6824710202000932877': '开发工具推荐',
'6824710203112423437': '树洞一下',
};
let url = '';
let json = null;
if (/^\d+$/.test(type)) {
url = `https://api.juejin.cn/recommend_api/v1/short_msg/topic`;
json = { id_type: 4, sort_type: 500, cursor: '0', limit: 20, topic_id: type };
} else {
url = `https://api.juejin.cn/recommend_api/v1/short_msg/${type}`;
json = { id_type: 4, sort_type: 200, cursor: '0', limit: 20 };
}
const response = await got({
method: 'post',
url: 'https://apinew.juejin.im/recommend_api/v1/short_msg/recommend',
json: { id_type: 4, sort_type: 300, cursor: '0', limit: 20 },
url,
json,
});
const items = response.data.data.map((item) => {
const content = item.msg_Info.content;
const title = content;
const guid = item.msg_id;
const link = `https://juejin.im/pin/${guid}`;
const link = `https://juejin.cn/pin/${guid}`;
const pubDate = new Date(parseInt(item.msg_Info.ctime) * 1000).toUTCString();
const author = item.author_user_info.user_name;
const imgs = item.msg_Info.pic_list.reduce((imgs, item) => {
@@ -36,7 +59,7 @@ module.exports = async (ctx) => {
});
ctx.state.data = {
title: '沸点 - 推荐',
title: `沸点 - ${title[type]}`,
link: 'https://juejin.im/pins/recommended',
item: items,
};