diff --git a/docs/en/journal.md b/docs/en/journal.md index 62c164b0b9c6f4..b7dd05b902d9af 100644 --- a/docs/en/journal.md +++ b/docs/en/journal.md @@ -47,6 +47,22 @@ See [Browse Content](https://pubs.acs.org) +## Annual Reviews + +### Journal + + + +The URL of the journal [Annual Review of Analytical Chemistry](https://www.annualreviews.org/journal/anchem) is `https://www.annualreviews.org/journal/anchem`, where `anchem` is the id of the journal, so the route for this journal is `/annualreviews/anchem`. + +::: tip Tip + +More jounals can be found in [Browse Journals](https://www.annualreviews.org/action/showPublications). + +::: + + + ## arXiv ### Search Keyword diff --git a/docs/journal.md b/docs/journal.md index e7ec38425d52bd..07086736421f7b 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -47,6 +47,22 @@ pageClass: routes +## Annual Reviews + +### Journal + + + +期刊 [Annual Review of Analytical Chemistry](https://www.annualreviews.org/journal/anchem) 的 URL 是 `https://www.annualreviews.org/journal/anchem`,其中 `anchem` 即为其期刊 id,故该期刊对应路由为 `/annualreviews/anchem`。 + +::: tip 提示 + +更多期刊可在 [Browse Journals](https://www.annualreviews.org/action/showPublications) 中找到。 + +::: + + + ## arXiv ### 搜索关键字 diff --git a/lib/v2/annualreviews/index.js b/lib/v2/annualreviews/index.js new file mode 100644 index 00000000000000..009ea6e8d2608f --- /dev/null +++ b/lib/v2/annualreviews/index.js @@ -0,0 +1,68 @@ +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://www.annualreviews.org'; + const apiRootUrl = `https://api.crossref.org`; + const feedUrl = `${rootUrl}/r/${id}_rss`; + const currentUrl = `${rootUrl}/toc/${id}/current`; + + const response = await got({ + method: 'get', + url: feedUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('entry') + .toArray() + .map((item) => { + item = $(item); + + const doi = item.find('id').text().split('doi=').pop(); + + return { + doi, + guid: doi, + title: item.find('title').text(), + link: item.find('link').attr('href').split('?')[0], + description: item.find('content').text(), + pubDate: parseDate(item.find('published').text()), + author: item + .find('author name') + .toArray() + .map((a) => $(a).text()) + .join(', '), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.guid, async () => { + const apiUrl = `${apiRootUrl}/works/${item.doi}`; + + const detailResponse = await got({ + method: 'get', + url: apiUrl, + }); + + item.description = detailResponse.data.message.abstract.replace(/jats:p>/g, 'p>'); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title') + .first() + .text() + .replace(/: Table of Contents/, ''), + description: $('subtitle').first().text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/annualreviews/maintainer.js b/lib/v2/annualreviews/maintainer.js new file mode 100644 index 00000000000000..b3ac0c5ab3acc6 --- /dev/null +++ b/lib/v2/annualreviews/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id': ['nczitzk'], +}; diff --git a/lib/v2/annualreviews/radar.js b/lib/v2/annualreviews/radar.js new file mode 100644 index 00000000000000..d796c50b74261a --- /dev/null +++ b/lib/v2/annualreviews/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'annualreviews.org': { + _name: 'Annual Reviews', + '.': [ + { + title: 'Journal', + docs: 'https://docs.rsshub.app/journal.html#annual-reviews-journal', + source: ['/journal/:id', '/'], + target: '/annualreviews/:id', + }, + ], + }, +}; diff --git a/lib/v2/annualreviews/router.js b/lib/v2/annualreviews/router.js new file mode 100644 index 00000000000000..641c23df3a1d0f --- /dev/null +++ b/lib/v2/annualreviews/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:id', require('./index')); +};