feat(route): add BioOne (#8994)

* feat(route): add BioOne

* fix typo

* fix typo
This commit is contained in:
Ethan Shen
2022-02-06 18:59:07 +08:00
committed by GitHub
parent d08f662103
commit ecbd064dbf
8 changed files with 103 additions and 9 deletions
+4
View File
@@ -41,6 +41,10 @@ Fill in parameter `query` with content after `http://export.arxiv.org/api/query?
<RouteEn author="nczitzk" example="/bioone/featured" path="/bioone/featured"/>
### Journals
<RouteEn author="nczitzk" example="/bioone/journals/acta-chiropterologica" path="/bioone/journals/:journal?" :paramsDesc="['Journals, can be found in URL']"/>
## Cell Journal
<RouteEn author="yech1990" example="/cell/cell/current" path="/cell/cell/:category" supportScihub="1" />
+4
View File
@@ -41,6 +41,10 @@ pageClass: routes
<Route author="nczitzk" example="/bioone/featured" path="/bioone/featured"/>
### Journals
<Route author="nczitzk" example="/bioone/journals/acta-chiropterologica" path="/bioone/journals/:journal?" :paramsDesc="['期刊名,可在期刊页地址栏中找到']"/>
## Cell
### 主刊
+1 -1
View File
@@ -3898,7 +3898,7 @@ router.get('/sznews/ranking', lazyloadRouteHandler('./routes/sznews/ranking'));
router.get('/shuax/project/:name?', lazyloadRouteHandler('./routes/shuax/project'));
// BioOne
router.get('/bioone/featured', lazyloadRouteHandler('./routes/bioone/featured'));
// router.get('/bioone/featured', lazyloadRouteHandler('./routes/bioone/featured'));
// Obsidian
router.get('/obsidian/announcements', lazyloadRouteHandler('./routes/obsidian/announcements'));
@@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://bioone.org';
@@ -10,9 +11,10 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const list = $('.items h4 a')
.slice(0, 10)
.map((_, item) => {
let items = $('.items h4 a')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.toArray()
.map((item) => {
item = $(item);
const link = item.attr('href');
@@ -20,11 +22,10 @@ module.exports = async (ctx) => {
title: item.text(),
link: link.indexOf('http') < 0 ? `${rootUrl}${link}` : link,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
@@ -34,7 +35,7 @@ module.exports = async (ctx) => {
item.description = content('#divARTICLECONTENTTop').html();
item.doi = content('meta[name="dc.Identifier"]').attr('content');
item.pubDate = new Date(content('meta[name="dc.Date"]').attr('content')).toUTCString();
item.pubDate = parseDate(content('meta[name="dc.Date"]').attr('content'));
return item;
})
+58
View File
@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const journal = ctx.params.journal ?? 'acta-chiropterologica';
const rootUrl = 'https://bioone.org';
const currentUrl = `${rootUrl}/journals/${journal}/current`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('.TOCLineItemBoldText')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.toArray()
.map((item) => {
item = $(item).parent();
return {
link: `${rootUrl}${item.attr('href')}`,
};
});
items = await Promise.all(
items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.ProceedingsArticleOpenAccessPanel').remove();
content('#divNotSignedSection, #rightRail').remove();
item.description = content('.panel-body').html();
item.title = content('meta[name="dc.Title"]').attr('content');
item.author = content('meta[name="dc.Creator"]').attr('content');
item.doi = content('meta[name="dc.Identifier"]').attr('content');
item.pubDate = parseDate(content('meta[name="dc.Date"]').attr('content'));
return item;
})
)
);
ctx.state.data = {
title: `${response.data.match(/'journalpaper', '(.*)'\)\\" class=\\"/)[1]} - BioOne`,
link: currentUrl,
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/featured': ['nczitzk'],
'/journals/:journal?': ['nczitzk'],
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'bioone.org': {
_name: 'BioOne',
'.': [
{
title: 'Featured articles',
docs: 'https://docs.rsshub.app/journal.html#bioone-featured-articles',
source: '/',
target: '/bioone/featured',
},
{
title: 'Journals',
docs: 'https://docs.rsshub.app/journal.html#bioone-journals',
source: ['/journals/:journal', '/'],
target: '/bioone/journals/:journal',
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/featured', require('./featured'));
router.get('/journals/:journal?', require('./journal'));
};