feat: add 36kr newsfeed (#4652)
This commit is contained in:
parent
f8340b79a0
commit
aa507ad43d
|
|
@ -6,6 +6,16 @@ pageClass: routes
|
|||
|
||||
## 36kr
|
||||
|
||||
### 资讯
|
||||
|
||||
<Route author="nczitzk" example="/36kr/news/latest" path="/36kr/news/:caty" :paramsDesc="['资讯分类']">
|
||||
|
||||
| 最新 | 推荐 | 创投 | 中概股 | 汽车 | 科技 | 企服 | 金融 | 生活 | 创新 | 房产 | 职场 | 其他 |
|
||||
| ------ | --------- | ------- | ------ | ------ | ---------- | ----------------- | ------- | ---- | -------- | ----------- | --------- | ----- |
|
||||
| latest | recommend | contact | ccs | travel | technology | enterpriseservice | banking | life | innovate | real_estate | workplace | other |
|
||||
|
||||
</Route>
|
||||
|
||||
### 快讯
|
||||
|
||||
<Route author="hillerliao" example="/36kr/newsflashes" path="/36kr/newsflashes" />
|
||||
|
|
|
|||
|
|
@ -1111,6 +1111,7 @@ router.get('/tingdiantz/nanjing', require('./routes/tingdiantz/nanjing'));
|
|||
// 36kr
|
||||
router.get('/36kr/search/article/:keyword', require('./routes/36kr/search/article'));
|
||||
router.get('/36kr/newsflashes', require('./routes/36kr/newsflashes'));
|
||||
router.get('/36kr/news/:caty', require('./routes/36kr/news'));
|
||||
router.get('/36kr/user/:uid', require('./routes/36kr/user'));
|
||||
router.get('/36kr/motif/:mid', require('./routes/36kr/motif'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const config = {
|
||||
latest: {
|
||||
link: '/information/web_news/latest',
|
||||
title: '最新',
|
||||
},
|
||||
recommend: {
|
||||
link: '/information/web_recommend',
|
||||
title: '推荐',
|
||||
},
|
||||
contact: {
|
||||
link: '/information/contact',
|
||||
title: '创投',
|
||||
},
|
||||
ccs: {
|
||||
link: '/information/ccs',
|
||||
title: '中概股',
|
||||
},
|
||||
travel: {
|
||||
link: '/information/travel',
|
||||
title: '汽车',
|
||||
},
|
||||
technology: {
|
||||
link: '/technology',
|
||||
title: '科技',
|
||||
},
|
||||
enterpriseservice: {
|
||||
link: '/information/enterpriseservice',
|
||||
title: '企服',
|
||||
},
|
||||
banking: {
|
||||
link: '/information/banking',
|
||||
title: '金融',
|
||||
},
|
||||
life: {
|
||||
link: '/information/happy_life',
|
||||
title: '生活',
|
||||
},
|
||||
innovate: {
|
||||
link: '/information/innovate',
|
||||
title: '创新',
|
||||
},
|
||||
estate: {
|
||||
link: '/information/real_estate',
|
||||
title: '房产',
|
||||
},
|
||||
workplace: {
|
||||
link: '/information/web_zhichang',
|
||||
title: '职场',
|
||||
},
|
||||
other: {
|
||||
link: '/information/other',
|
||||
title: '其他',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const cfg = config[ctx.params.caty];
|
||||
if (!cfg) {
|
||||
throw Error('Bad category. See <a href="https://docs.rsshub.app/government.html#bei-jing-shi-wei-sheng-jian-kang-wei-yuan-hui">docs</a>');
|
||||
}
|
||||
|
||||
const newsUrl = url.resolve(`https://36kr.com/`, cfg.link);
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: newsUrl,
|
||||
});
|
||||
|
||||
const data = JSON.parse(response.data.match(/<script>window\.initialState=(.*?)<\/script>/)[1]);
|
||||
|
||||
const informationList = data.information.informationList.itemList.map((item) => ({
|
||||
title: item.templateMaterial.widgetTitle,
|
||||
link: `https://36kr.com/p/${item.itemId}`,
|
||||
pubDate: new Date(item.templateMaterial.publishTime).toUTCString(),
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `36氪资讯 - ${cfg.title}`,
|
||||
link: newsUrl,
|
||||
item: await Promise.all(
|
||||
informationList.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const contentResponse = await got({ method: 'get', url: item.link });
|
||||
const content = cheerio.load(contentResponse.data);
|
||||
item.description = content('div.common-width.content.articleDetailContent.kr-rich-text-wrapper').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue