diff --git a/docs/en/journal.md b/docs/en/journal.md index d268f1fe33..f1637cf847 100644 --- a/docs/en/journal.md +++ b/docs/en/journal.md @@ -201,6 +201,12 @@ Subscribe to the cover images of the Nature journals, and get the latest publica +## ScienceDirect + +### Journal + + + ## Science Journal ### Current Issue diff --git a/docs/journal.md b/docs/journal.md index b136b90a4f..f477e75dda 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -209,6 +209,12 @@ _仅支持 Science 主刊_ +## ScienceDirect + +### Journal + + + ## Stork 文献鸟订阅 ### 关键词 diff --git a/lib/v2/sciencedirect/journal.js b/lib/v2/sciencedirect/journal.js new file mode 100644 index 0000000000..6afe89b78b --- /dev/null +++ b/lib/v2/sciencedirect/journal.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const rootUrl = 'https://sciencedirect.com'; + const currentUrl = `${rootUrl}/journal/${id}/articles-in-press`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const issn = response.data.match(/ISSN(\d{8})'/)[1]; + + const apiUrl = `${rootUrl}/journal/${issn}/articles-in-press/articles?path=/journal/${id}/articles-in-press&title=${id}`; + + const apiResponse = await got({ + method: 'get', + url: apiUrl, + headers: { + cookie: response.headers['set-cookie'].map((cookie) => cookie.split(';Version=1;')[0]).join('; '), + }, + }); + + const list = apiResponse.data.data.results.map((item) => ({ + doi: item.doi, + title: item.title, + link: `${rootUrl}${item.href}`, + pubDate: parseDate(item.coverDateStart), + enclosure_url: `${rootUrl}${item.pdfDownload.url}`, + author: item.authors.map((author) => `${author.givenName} ${author.surname}`).join(', '), + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + const abstracts = content('.Abstracts').html() ?? ''; + const keywords = content('.Keywords').html() ?? ''; + + item.description = abstracts + keywords; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${response.data.match(/\\"displayName\\":\\"(.*?)\\",\\"/)[1]} - ScienceDirect`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/sciencedirect/maintainer.js b/lib/v2/sciencedirect/maintainer.js new file mode 100644 index 0000000000..be3977785f --- /dev/null +++ b/lib/v2/sciencedirect/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/journal/:id': ['nczitzk'], +}; diff --git a/lib/v2/sciencedirect/radar.js b/lib/v2/sciencedirect/radar.js new file mode 100644 index 0000000000..904012d36d --- /dev/null +++ b/lib/v2/sciencedirect/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sciencedirect.com': { + _name: 'ScienceDirect', + '.': [ + { + title: 'Journal', + docs: 'https://docs.rsshub.app/journal.html#sciencedirect-journal', + source: ['/journal/:id', '/'], + target: '/sciencedirect/journal/:id', + }, + ], + }, +}; diff --git a/lib/v2/sciencedirect/router.js b/lib/v2/sciencedirect/router.js new file mode 100644 index 0000000000..85289aacef --- /dev/null +++ b/lib/v2/sciencedirect/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/journal/:id', require('./journal')); +};