feat(route): add Caa.reviews (#9842)

* feat(route): add Caa.reviews

* Update docs/en/journal.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update docs/en/journal.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update docs/journal.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/caareviews/book.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/caareviews/essay.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/caareviews/exhibition.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/caareviews/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix(route): add doi

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
Fatpandac
2022-05-29 07:23:05 +08:00
committed by GitHub
co-authored by Tony
parent 8a567d5cd4
commit 437fb82858
10 changed files with 155 additions and 0 deletions
+13
View File
@@ -45,6 +45,19 @@ Fill in parameter `query` with content after `http://export.arxiv.org/api/query?
<RouteEn author="nczitzk" example="/bioone/journals/acta-chiropterologica" path="/bioone/journals/:journal?" :paramsDesc="['Journals, can be found in URL']"/>
## caa.reviews
### Book Reviews
<RouteEn author="Fatpandac" example="/caareviews/book" path="/caareviews/book"/>
### Exhibition Reviews
<RouteEn author="Fatpandac" example="/caareviews/exhibition" path="/caareviews/exhibition"/>
### Essays
<RouteEn author="Fatpandac" example="/caareviews/essay" path="/caareviews/essay"/>
## Cell Journal
<RouteEn author="yech1990" example="/cell/cell/current" path="/cell/cell/:category" supportScihub="1" />
+14
View File
@@ -45,6 +45,20 @@ pageClass: routes
<Route author="nczitzk" example="/bioone/journals/acta-chiropterologica" path="/bioone/journals/:journal?" :paramsDesc="['期刊名,可在期刊页地址栏中找到']"/>
## caa.reviews
### Book Reviews
<Route author="Fatpandac" example="/caareviews/book" path="/caareviews/book"/>
### Exhibition Reviews
<Route author="Fatpandac" example="/caareviews/exhibition" path="/caareviews/exhibition"/>
### Essays
<Route author="Fatpandac" example="/caareviews/essay" path="/caareviews/essay"/>
## Cell
### 主刊
+14
View File
@@ -0,0 +1,14 @@
const { rootUrl, getList, getItems } = require('./utils');
module.exports = async (ctx) => {
const url = `${rootUrl}/reviews/book`;
const list = await getList(url);
const items = await getItems(ctx, list);
ctx.state.data = {
title: 'Book Reviews',
link: url,
item: items,
};
};
+14
View File
@@ -0,0 +1,14 @@
const { rootUrl, getList, getItems } = require('./utils');
module.exports = async (ctx) => {
const url = `${rootUrl}/reviews/essay`;
const list = await getList(url);
const items = await getItems(ctx, list);
ctx.state.data = {
title: 'Essays',
link: url,
item: items,
};
};
+14
View File
@@ -0,0 +1,14 @@
const { rootUrl, getList, getItems } = require('./utils');
module.exports = async (ctx) => {
const url = `${rootUrl}/reviews/exhibition`;
const list = await getList(url);
const items = await getItems(ctx, list);
ctx.state.data = {
title: 'Exhibition Reviews',
link: url,
item: items,
};
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
'/book': ['Fatpandac'],
'/essay': ['Fatpandac'],
'/exhibition': ['Fatpandac'],
};
+25
View File
@@ -0,0 +1,25 @@
module.exports = {
'caareviews.org': {
_name: 'caa.reviews',
'.': [
{
title: 'Book Reviews',
docs: 'https://docs.rsshub.app/journal.html#caa-reviews',
source: ['/reviews/book'],
target: '/caareviews/book',
},
{
title: 'Exhibition Reviews',
docs: 'https://docs.rsshub.app/journal.html#caa-reviews',
source: ['/reviews/exhibition'],
target: '/caareviews/exhibition',
},
{
title: 'Essays',
docs: 'https://docs.rsshub.app/journal.html#caa-reviews',
source: ['/reviews/essay'],
target: '/caareviews/essay',
},
],
},
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = function (router) {
router.get('/book', require('./book'));
router.get('/essay', require('./essay'));
router.get('/exhibition', require('./exhibition'));
};
+2
View File
@@ -0,0 +1,2 @@
<img src="{{ coverUrl }}">
{{@ content}}
+49
View File
@@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const rootUrl = 'http://www.caareviews.org';
const getList = async (url) => {
const response = await got(url);
const $ = cheerio.load(response.data);
const list = $('#infinite-content > div')
.map((_index, item) => ({
title: $(item).find('div.title').text().trim(),
link: new URL($(item).find('div.title > em > a').attr('href'), rootUrl).href,
author: $(item).find('div.contributors').text().trim(),
}))
.get();
return list;
};
const getItems = async (ctx, list) =>
await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const $ = cheerio.load(detailResponse.data);
const coverUrl = new URL($('div.cover > a').attr('href'), rootUrl).href;
const content = $('div.content.full-review').html();
item.description = art(path.join(__dirname, 'templates/utils.art'), {
coverUrl,
content,
});
$('div.review_heading').remove();
item.pubDate = parseDate($('div.header-text > div.clearfix').text());
item.doi = $('div.crossref > a').attr('href').replace('http://dx.doi.org/', '');
return item;
})
)
);
module.exports = {
rootUrl,
getList,
getItems,
};