feat: add MedSci (#5386)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen 2020-08-19 04:38:10 +08:00 committed by GitHub
parent 2a9f35b78d
commit c1e38bd2fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 0 deletions

View File

@ -801,6 +801,12 @@ area 分区选项
</Route>
## 梅斯医学 MedSci
### 推荐
<Route author="nczitzk" example="/medsci/recommend" path="/medsci/recommend"/>
## 摩根大通研究所
### 新闻

View File

@ -3062,6 +3062,9 @@ router.get('/telecompaper/news/:caty/:year?/:country?/:type?/:keyword?', require
// 水木社区
router.get('/newsmth/account/:id', require('./routes/newsmth/account'));
// 梅斯医学
router.get('/medsci/recommend', require('./routes/medsci/recommend'));
// Wallpaperhub
router.get('/wallpaperhub', require('./routes/wallpaperhub/index'));

View File

@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const currentUrl = 'http://www.medsci.cn';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.composs-panel-inner div.composs-blog-list div.item div.item-content h2 a.ms-link')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
pubDate: date(item.parent().parent().find('span.item-meta-item').eq(0).text()),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const publishedTime = detailResponse.data.match(/"publishedTime":"(.*?)","publishedTimeString"/);
const type = item.link.split('/')[3];
item.pubDate = publishedTime ? new Date(publishedTime[1]).toUTCString() : item.pubDate;
item.description = type === 'article' ? content('div.article-content-box').html() : content('shortcode-content').html();
return item;
})
)
);
ctx.state.data = {
title: '梅斯医学 - 推荐',
link: currentUrl,
item: items,
};
};