diff --git a/docs/en/journal.md b/docs/en/journal.md index 66b5b3cdd5..c4ff67ccb6 100644 --- a/docs/en/journal.md +++ b/docs/en/journal.md @@ -68,6 +68,10 @@ pageClass: routes ## Search Engine +### PubMed Trending + + + ### X-MOL Platform - News diff --git a/docs/journal.md b/docs/journal.md index 9cb5f88337..3a0e9881c0 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -6,6 +6,10 @@ pageClass: routes ## 聚合平台 +### PubMed-热门文章 + + + ### X-MOL 平台-新闻 diff --git a/lib/router.js b/lib/router.js index 15024695e2..111ae22fbd 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1987,6 +1987,9 @@ router.get('/hatena/anonymous_diary/archive', require('./routes/hatena/anonymous router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion')); router.get('/kaggle/competitions/:category?', require('./routes/kaggle/competitions')); +// PubMed Trending +router.get('/pubmed/trending', require('./routes/pubmed/trending')); + // eLife [Sci Journal] router.get('/elife/latest', require('./routes/elife/latest')); router.get('/elife/:tid', require('./routes/elife/subject')); diff --git a/lib/routes/pubmed/trending.js b/lib/routes/pubmed/trending.js new file mode 100644 index 0000000000..e777af3165 --- /dev/null +++ b/lib/routes/pubmed/trending.js @@ -0,0 +1,73 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const date = require('@/utils/date'); + +const base = 'https://www.ncbi.nlm.nih.gov'; + +module.exports = async (ctx) => { + const link = `${base}/pubmed/trending/`; + const response = await got.get(encodeURI(link)); + const pageCapture = cheerio.load(response.data); + + const list = pageCapture('.content div.rprt > div.rslt').get(); + const out = await Promise.all( + list.map(async (elem) => { + const $ = cheerio.load(elem); + const title = $('p > a').text(); + const partial = $('p > a').attr('href'); + const address = url.resolve(base, partial); + const author = $('div.supp > p.desc').text(); + const pubDate = date( + $('div.supp > p.details') + .text() + .split('. ')[1] + ); + + const item = { + title, + author, + pubDate, + link: encodeURI(address), + }; + + const value = await ctx.cache.get(address); + if (value) { + item.description = value; + } else { + const detail = await got.get(item.link); + const detailCapture = cheerio.load(detail.data); + + let authorContents = ''; + if (author !== '') { + authorContents = ` +
+ ${author} +
+ `; + } + const abs = detailCapture('div.abstr > div').html(); + let absContents = ''; + if (abs !== null) { + absContents = ` +
+

Abstract

+

${abs}

+
+ `; + } + item.description = authorContents + absContents; + ctx.cache.set(address, item.description); + } + + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: 'PubMed | Trending Articles', + description: 'Trending Articles from PubMed Website', + link: link, + item: out, + }; +}; diff --git a/lib/routes/zhishifenzi/depth.js b/lib/routes/zhishifenzi/depth.js index a09e854292..1b712a28bd 100644 --- a/lib/routes/zhishifenzi/depth.js +++ b/lib/routes/zhishifenzi/depth.js @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const list = pageCapture('div.inner_depth_list > ul > li').get(); const out = await Promise.all( - list.slice(0, 3).map(async (elem) => { + list.map(async (elem) => { const $ = cheerio.load(elem); const title = $('h5 > a').text(); const partial = $('h5 > a').attr('href');