diff --git a/docs/new-media.md b/docs/new-media.md index 71884c9e0..69245a860 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -801,6 +801,12 @@ area 分区选项 +## 梅斯医学 MedSci + +### 推荐 + + + ## 摩根大通研究所 ### 新闻 diff --git a/lib/router.js b/lib/router.js index dd26d5979..4b9c03525 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/medsci/recommend.js b/lib/routes/medsci/recommend.js new file mode 100644 index 000000000..9f5ad4789 --- /dev/null +++ b/lib/routes/medsci/recommend.js @@ -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, + }; +};