Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add Annual Reviews Journals #11898

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/en/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ See [Browse Content](https://pubs.acs.org)

</RouteEn>

## Annual Reviews

### Journal

<RouteEn author="nczitzk" example="/annualreviews/anchem" path="/annualreviews/:id" :paramsDesc="['Journal id, can be found in URL']" supportScihub="1">

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).

:::

</RouteEn>

## arXiv

### Search Keyword
Expand Down
16 changes: 16 additions & 0 deletions docs/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ pageClass: routes

</Route>

## Annual Reviews

### Journal

<Route author="nczitzk" example="/annualreviews/anchem" path="/annualreviews/:id" :paramsDesc="['期刊 id,可在对应期刊页 URL 中找到']" supportScihub="1">

期刊 [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) 中找到。

:::

</Route>

## arXiv

### 搜索关键字
Expand Down
68 changes: 68 additions & 0 deletions lib/v2/annualreviews/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/annualreviews/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:id': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/annualreviews/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/annualreviews/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:id', require('./index'));
};