feat(route): add bioone featured articles (#6990)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-03-02 12:46:36 +08:00
committed by GitHub
parent acd6772528
commit 2480458988
4 changed files with 65 additions and 0 deletions

View File

@@ -35,6 +35,12 @@ Fill in parameter `query` with content after `http://export.arxiv.org/api/query?
</RouteEn>
## BioOne
### Featured articles
<RouteEn author="nczitzk" example="/bioone/featured" path="/bioone/featured"/>
## Cell Journal
<RouteEn author="yech1990" example="/cell/cell/current" path="/cell/cell/:category" supportScihub="1" />

View File

@@ -35,6 +35,12 @@ pageClass: routes
</Route>
## BioOne
### Featured articles
<Route author="nczitzk" example="/bioone/featured" path="/bioone/featured"/>
## Cell
### 主刊

View File

@@ -3926,6 +3926,9 @@ router.get('/tianyancha/hot', require('./routes/tianyancha/hot'));
// King Arthur
router.get('/kingarthur/:type', require('./routes/kingarthur/index'));
// BioOne
router.get('/bioone/featured', require('./routes/bioone/featured'));
// Obsidian
router.get('/obsidian/announcements', require('./routes/obsidian/announcements'));

View File

@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://bioone.org';
const response = await got({
method: 'get',
url: rootUrl,
});
const $ = cheerio.load(response.data);
const list = $('.items h4 a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const link = item.attr('href');
return {
title: item.text(),
link: link.indexOf('http') < 0 ? `${rootUrl}${link}` : link,
};
})
.get();
const items = await Promise.all(
list.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);
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();
return item;
})
)
);
ctx.state.data = {
title: 'Featured articles - BioOne',
link: rootUrl,
item: items,
};
};