Files
RSSHub/lib/v2/juejin/category.js
CancerGary 950bfa61ed feat(route): add juejin news (#7969)
* feat(route): add juejin news

* feat(route): add juejin news

* fix(route): juejin news pubDate

* fix: fix utility

* refactor: migrate to v2

* fix: typo

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2022-05-20 01:55:18 +08:00

40 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
const util = require('./utils');
module.exports = async (ctx) => {
const { category } = ctx.params;
const idResponse = await got({
method: 'get',
url: 'https://api.juejin.cn/tag_api/v1/query_category_briefs?show_type=0',
});
const cat = idResponse.data.data.find((item) => item.category_url === category);
const id = cat.category_id;
const response = await got({
method: 'post',
url: 'https://api.juejin.cn/recommend_api/v1/article/recommend_cate_feed',
json: {
id_type: 2,
sort_type: 300,
cate_id: id,
cursor: '0',
limit: 20,
},
});
let originalData = [];
if (response.data.data) {
originalData = response.data.data;
}
const resultItems = await util.ProcessFeed(originalData, ctx.cache);
ctx.state.data = {
title: `掘金 ${cat.category_name}`,
link: `https://juejin.cn/${category}`,
description: `掘金 ${cat.category_name}`,
item: resultItems,
};
};