feat: add 36kr newsfeed by users and subjects (#4653)
This commit is contained in:
parent
725a733b2a
commit
e5995cc2cc
|
|
@ -10,6 +10,14 @@ pageClass: routes
|
|||
|
||||
<Route author="hillerliao" example="/36kr/newsflashes" path="/36kr/newsflashes" />
|
||||
|
||||
### 用户文章
|
||||
|
||||
<Route author="nczitzk" example="/36kr/user/747305693" path="/36kr/user/:uid" :paramsDesc="['用户ID']" />
|
||||
|
||||
### 主题文章
|
||||
|
||||
<Route author="nczitzk" example="/36kr/motif/452" path="/36kr/motif/:mid" :paramsDesc="['主题ID']" />
|
||||
|
||||
### 搜索文章
|
||||
|
||||
<Route author="xyqfer kt286" example="/36kr/search/article/ofo" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
|
||||
|
|
|
|||
|
|
@ -1107,6 +1107,8 @@ 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/user/:uid', require('./routes/36kr/user'));
|
||||
router.get('/36kr/motif/:mid', require('./routes/36kr/motif'));
|
||||
|
||||
// PMCAFF
|
||||
router.get('/pmcaff/list/:typeid', require('./routes/pmcaff/list'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const motifUrl = `https://36kr.com/motif/${ctx.params.mid}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: motifUrl,
|
||||
});
|
||||
const data = JSON.parse(response.data.match(/"motifDetailData":{"code":0,"data":(.*?)},"channel":/)[1]);
|
||||
|
||||
const motifInfo = data.motifInfo.data;
|
||||
const motifArticleList = data.motifArticleList.data.itemList;
|
||||
const articleList = motifArticleList.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氪专题 - ${motifInfo.categoryTitle}`,
|
||||
link: motifUrl,
|
||||
item: await Promise.all(
|
||||
articleList.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;
|
||||
})
|
||||
)
|
||||
),
|
||||
description: `${motifInfo.categoryTitle}`,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const userUrl = `https://36kr.com/user/${ctx.params.uid}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: userUrl,
|
||||
});
|
||||
const data = JSON.parse(response.data.match(/"authorDetailData":{"code":0,"data":(.*?)},"channel":/)[1]);
|
||||
|
||||
const authorInfo = data.authorInfo.data;
|
||||
const authorArticleList = data.authorArticleList.data.itemList;
|
||||
const articleList = authorArticleList.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氪用户 - ${authorInfo.userNick}`,
|
||||
link: userUrl,
|
||||
item: await Promise.all(
|
||||
articleList.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;
|
||||
})
|
||||
)
|
||||
),
|
||||
description: `${authorInfo.label} | ${authorInfo.summary}`,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue