From 09023ccae75ee7d1c920c14123bd03bb320fcce7 Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 27 Nov 2021 17:14:24 +0800 Subject: [PATCH] feat(route): add ELSEVIER journal (#8583) --- docs/en/journal.md | 14 ++++ docs/journal.md | 14 ++++ lib/v2/elsevier/latest.js | 87 +++++++++++++++++++++++ lib/v2/elsevier/maintainer.js | 4 ++ lib/v2/elsevier/radar.js | 19 +++++ lib/v2/elsevier/router.js | 4 ++ lib/v2/elsevier/templates/description.art | 9 +++ lib/v2/elsevier/volume.js | 75 +++++++++++++++++++ 8 files changed, 226 insertions(+) create mode 100644 lib/v2/elsevier/latest.js create mode 100644 lib/v2/elsevier/maintainer.js create mode 100644 lib/v2/elsevier/radar.js create mode 100644 lib/v2/elsevier/router.js create mode 100644 lib/v2/elsevier/templates/description.art create mode 100644 lib/v2/elsevier/volume.js diff --git a/docs/en/journal.md b/docs/en/journal.md index 5725805b1..4335e028c 100644 --- a/docs/en/journal.md +++ b/docs/en/journal.md @@ -68,6 +68,20 @@ Including 'cell', 'cancer-cell', 'cell-chemical-biology', 'cell-host-microbe', ' +## ELSEVIER + +### Latest Research + + + + + +### Special Volume + + + + + ## Google Scholar ### Keywords Monitoring diff --git a/docs/journal.md b/docs/journal.md index 01f276a3f..2dd5fc9ea 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -80,6 +80,20 @@ pageClass: routes +## ELSEVIER + +### 最新文章 + + + + + +### 指定卷中的文章 + + + + + ## IEEE Xplore ### 作者 diff --git a/lib/v2/elsevier/latest.js b/lib/v2/elsevier/latest.js new file mode 100644 index 000000000..a67fef35e --- /dev/null +++ b/lib/v2/elsevier/latest.js @@ -0,0 +1,87 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const config = require('@/config').value; +const path = require('path'); +const { art } = require('@/utils/render'); + +module.exports = async (ctx) => { + const host = 'https://www.sciencedirect.com'; + const journal = ctx.params.journal; + const hostUrl = host.concat('/journal/', journal); + const resp = await got(host); + const cookie = resp.headers['set-cookie'].join(' '); + const headers = { + Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'zh-CN,zh;q=0.9', + Referer: 'https://id.elsevier.com/', + Host: host.replace('https://', ''), + 'User-Agent': config.ua, + cookie, + }; + + const preResponse = await got({ + method: 'get', + url: hostUrl, + headers, + }); + const $1 = cheerio.load(preResponse.data); + const jrnlName = $1('.anchor.js-title-link').text(); + const ltstUrl = host.concat($1('.anchor.js-volume').attr('href')); + let volume = ''; + if (ltstUrl.match('suppl') !== null) { + volume = 'Volume ' + ltstUrl.match('vol/(.*)/suppl')[1]; + } else if (ltstUrl.match('issue') !== null) { + volume = 'Volume ' + ltstUrl.match('vol/(.*)/issue')[1] + ' Issue ' + ltstUrl.match('/issue/(.*)')[1]; + } + + const response = await got({ + method: 'get', + url: ltstUrl, + headers, + }); + const $ = cheerio.load(response.data); + const list = $('.js-article') + .map((_, item) => { + const title = $(item).find('.js-article-title').text(); + const authors = $(item).find('.js-article__item__authors').text(); + const link = $(item).find('.article-content-title').attr('href'); + const id = $(item).find('.article-content-title').attr('id'); + return { + title, + link, + id, + authors, + volume, + }; + }) + .get(); + + const renderDesc = (item) => + art(path.join(__dirname, 'templates/description.art'), { + item, + }); + await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const itemResponse = await got({ + method: 'get', + url: host.concat('/science/article/pii/', item.id), + headers, + }); + const content = cheerio.load(itemResponse.data); + content('.section-title').remove(); + const doi = content('.doi').attr('href').replace('https://doi.org/', ''); + item.doi = doi; + item.abstract = content('.abstract.author').html(); + item.description = renderDesc(item); + return item; + }) + ) + ); + ctx.state.data = { + title: jrnlName.concat(' - Latest'), + link: hostUrl, + item: list, + }; +}; diff --git a/lib/v2/elsevier/maintainer.js b/lib/v2/elsevier/maintainer.js new file mode 100644 index 000000000..2bcee89a8 --- /dev/null +++ b/lib/v2/elsevier/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/:journal/latest': ['Derekmini', 'sunsunwolf-swb'], + '/:journal/vol/:id': ['Derekmini', 'sunsunwolf-swb'], +}; diff --git a/lib/v2/elsevier/radar.js b/lib/v2/elsevier/radar.js new file mode 100644 index 000000000..7aa8f02c4 --- /dev/null +++ b/lib/v2/elsevier/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'sciencedirect.com': { + _name: 'Elsevier', + www: [ + { + title: 'latest', + docs: 'https://docs.rsshub.app/journal.html#Elsevier', + source: '/journal/:journal/*', + target: '/elsevier/:journal/latest', + }, + { + title: 'volume', + docs: 'https://docs.rsshub.app/journal.html#Elsevier', + source: '/journal/:journal/vol/:id', + target: '/elsevier/:journal/vol/:id', + }, + ], + }, +}; diff --git a/lib/v2/elsevier/router.js b/lib/v2/elsevier/router.js new file mode 100644 index 000000000..7bb0020f4 --- /dev/null +++ b/lib/v2/elsevier/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/:journal/latest', require('./latest')); + router.get('/:journal/vol/:id', require('./volume')); +}; diff --git a/lib/v2/elsevier/templates/description.art b/lib/v2/elsevier/templates/description.art new file mode 100644 index 000000000..24cefcd5e --- /dev/null +++ b/lib/v2/elsevier/templates/description.art @@ -0,0 +1,9 @@ +

+ {{ item.title }}
+ {{ item.authors }}
+ https://doi.org/{{ item.doi }}
+ {{ item.volume }}
+

+

+ {{ item.abstract }}
+

\ No newline at end of file diff --git a/lib/v2/elsevier/volume.js b/lib/v2/elsevier/volume.js new file mode 100644 index 000000000..3b4d19d5f --- /dev/null +++ b/lib/v2/elsevier/volume.js @@ -0,0 +1,75 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const config = require('@/config').value; +const path = require('path'); +const { art } = require('@/utils/render'); + +module.exports = async (ctx) => { + const host = 'https://www.sciencedirect.com'; + const journal = ctx.params.journal; + const volume = 'Volume ' + ctx.params.id.replace('-', ' Issue '); + const volUrl = 'https://www.sciencedirect.com/journal/' + journal + '/vol/' + ctx.params.id.replace('-', '/issue/'); + const resp = await got(host); + const cookie = resp.headers['set-cookie'].join(' '); + const headers = { + Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'zh-CN,zh;q=0.9', + Referer: 'https://id.elsevier.com/', + Host: host.replace('https://', ''), + 'User-Agent': config.ua, + cookie, + }; + + const response = await got({ + method: 'get', + url: volUrl, + headers, + }); + const $ = cheerio.load(response.data); + const jrnlName = $('.anchor.js-title-link').text(); + const list = $('.js-article') + .map((_, item) => { + const title = $(item).find('.js-article-title').text(); + const authors = $(item).find('.js-article__item__authors').text(); + const link = $(item).find('.article-content-title').attr('href'); + const id = $(item).find('.article-content-title').attr('id'); + return { + title, + link, + id, + authors, + volume, + }; + }) + .get(); + + const renderDesc = (item) => + art(path.join(__dirname, 'templates/description.art'), { + item, + }); + await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const itemResponse = await got({ + method: 'get', + url: 'https://www.sciencedirect.com/science/article/pii/' + item.id, + headers, + }); + const content = cheerio.load(itemResponse.data); + content('.section-title').remove(); + const doi = content('.doi').attr('href').replace('https://doi.org/', ''); + item.doi = doi; + item.abstract = content('.abstract.author').html(); + item.description = renderDesc(item); + return item; + }) + ) + ); + + ctx.state.data = { + title: jrnlName.concat(' - ', volume), + link: volUrl, + item: list, + }; +};