diff --git a/docs/en/journal.md b/docs/en/journal.md index 190401f70e3456..55fc8f4512abb8 100644 --- a/docs/en/journal.md +++ b/docs/en/journal.md @@ -262,9 +262,19 @@ Subscribe to the cover images of the Nature journals, and get the latest publica ## PubMed -### Trending +### Trending articles - + + +::: tip Tip + +For the parameter **filter**, the `filter` parameter in the URL should be split into a string by `,`, here is an example. + +In , the filter parameters are `simsearch1.fha`, `pubt.clinicaltrial`, and `pubt.randomizedcontrolledtrial`. Therefore, the filter corresponding to the route should be filled with `simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial`, and the route is [`/pubmed/trending/simsearch1.fha,pubt .clinicaltrial,pubt.randomizedcontrolledtrial`](https://rsshub.app/pubmed/trending/simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial) + +::: + + ## Science Journal diff --git a/docs/journal.md b/docs/journal.md index af63f42fb99128..d7786a4f37593b 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -231,9 +231,19 @@ pageClass: routes ## PubMed -### 热门文章 +### Trending articles - + + +::: tip 提示 + +对于参数 **过滤条件**,应将 URL 中的 filter 参数用 `,` 分割成一个字段填入,下面是一个例子。 + + 中 filter 参数有 `simsearch1.fha` `pubt.clinicaltrial` `pubt.randomizedcontrolledtrial` 三者。所以,对应到路由的 filter 应填入 `simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial`,于是可获得路由 [`/pubmed/trending/simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial`](https://rsshub.app/pubmed/trending/simsearch1.fha,pubt.clinicaltrial,pubt.randomizedcontrolledtrial) + +::: + + ## Science 系列 diff --git a/lib/router.js b/lib/router.js index 5b7b4469a7d715..2054f1034b6b9a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2182,7 +2182,7 @@ router.get('/kaggle/competitions/:category?', lazyloadRouteHandler('./routes/kag router.get('/kaggle/user/:user', lazyloadRouteHandler('./routes/kaggle/user')); // PubMed Trending -router.get('/pubmed/trending', lazyloadRouteHandler('./routes/pubmed/trending')); +// router.get('/pubmed/trending', lazyloadRouteHandler('./routes/pubmed/trending')); // 领科 (linkresearcher.com) router.get('/linkresearcher/:params', lazyloadRouteHandler('./routes/linkresearcher/index')); diff --git a/lib/routes/pubmed/trending.js b/lib/routes/pubmed/trending.js deleted file mode 100644 index 7307ac95e86033..00000000000000 --- a/lib/routes/pubmed/trending.js +++ /dev/null @@ -1,65 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); -const date = require('@/utils/date'); - -const base = 'https://pubmed.ncbi.nlm.nih.gov'; - -module.exports = async (ctx) => { - const link = `${base}/trending/`; - const response = await got.get(encodeURI(link)); - const pageCapture = cheerio.load(response.data); - - const list = pageCapture('.docsum-content') - .map((_, elem) => { - const $ = cheerio.load(elem); - const partial = $('a').attr('href'); - return { - title: $('a').text().trim(), - link: url.resolve(base, partial), - author: $('.full-authors').text(), - }; - }) - .get(); - - const out = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detail = await got.get(item.link); - const detailCapture = cheerio.load(detail.data); - - item.doi = detailCapture('meta[name="citation_doi"]').attr('content'); - item.pubDate = date(detailCapture('meta[name="citation_date"]').attr('content')); - - let authorContents = ''; - if (item.author !== '') { - authorContents = ` -
- ${item.author} -
- `; - } - const abs = detailCapture('#enc-abstract').html(); - let absContents = ''; - if (abs !== null) { - absContents = ` -
-

Abstract

-

${abs}

-
- `; - } - item.description = authorContents + absContents; - - return item; - }) - ) - ); - - ctx.state.data = { - title: 'PubMed | Trending Articles', - description: 'Trending Articles from PubMed Website', - link, - item: out, - }; -}; diff --git a/lib/v2/pubmed/maintainer.js b/lib/v2/pubmed/maintainer.js new file mode 100644 index 00000000000000..521275e35a5434 --- /dev/null +++ b/lib/v2/pubmed/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/trending/:filters?': ['nczitzk'], +}; diff --git a/lib/v2/pubmed/radar.js b/lib/v2/pubmed/radar.js new file mode 100644 index 00000000000000..9140945c18188c --- /dev/null +++ b/lib/v2/pubmed/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'pubmed.ncbi.nlm.nih.gov': { + _name: 'PubMed', + '.': [ + { + title: 'Trending articles', + docs: 'https://docs.rsshub.app/journal.html#pubmed-trending-articles', + source: ['/trending', '/'], + target: (params, url) => `/pubmed/trending/${new URL(url).searchParams.getAll('filter').join(',')}`, + }, + ], + }, +}; diff --git a/lib/v2/pubmed/router.js b/lib/v2/pubmed/router.js new file mode 100644 index 00000000000000..5db58ad1e58f6c --- /dev/null +++ b/lib/v2/pubmed/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/trending/:filters?', require('./trending')); +}; diff --git a/lib/v2/pubmed/templates/description.art b/lib/v2/pubmed/templates/description.art new file mode 100644 index 00000000000000..c4b8e232b99721 --- /dev/null +++ b/lib/v2/pubmed/templates/description.art @@ -0,0 +1,7 @@ +{{ if authors }} +{{@ authors }} +{{ /if}} +
+{{ if abs }} +{{@ abs }} +{{ /if}} \ No newline at end of file diff --git a/lib/v2/pubmed/trending.js b/lib/v2/pubmed/trending.js new file mode 100644 index 00000000000000..3e761efd7df99d --- /dev/null +++ b/lib/v2/pubmed/trending.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const filters = ctx.params.filters; + + const rootUrl = 'https://pubmed.ncbi.nlm.nih.gov'; + const currentUrl = `${rootUrl}/trending${filters ? `?filter=${filters.replace(/,/g, '&filter=')}` : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('a[data-article-id]') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}/${item.attr('data-article-id')}`, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.doi = content('meta[name="citation_doi"]').attr('content'); + item.pubDate = parseDate(content('meta[name="citation_date"]').attr('content')); + item.description = art(path.join(__dirname, 'templates/description.art'), { + authors: content('.authors-list').html(), + abs: content('#enc-abstract').html(), + }); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'Trending page - PubMed', + link: currentUrl, + item: items, + }; +};