fix(route): bioone (#11699)

This commit is contained in:
Tony 2023-01-27 01:13:34 +11:00 committed by GitHub
parent 8355e32913
commit 11ff4a2f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 16 deletions

View File

@ -4,9 +4,10 @@ const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://bioone.org';
const response = await got({
method: 'get',
url: rootUrl,
const response = await got(rootUrl, {
https: {
rejectUnauthorized: false,
},
});
const $ = cheerio.load(response.data);
@ -16,20 +17,21 @@ module.exports = async (ctx) => {
.toArray()
.map((item) => {
item = $(item);
const link = item.attr('href');
const link = item.attr('href').split('?')[0];
return {
title: item.text(),
link: link.indexOf('http') < 0 ? `${rootUrl}${link}` : link,
link: !link.includes('http') ? `${rootUrl}${link}` : link,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const detailResponse = await got(item.link, {
https: {
rejectUnauthorized: false,
},
});
const content = cheerio.load(detailResponse.data);

View File

@ -7,15 +7,16 @@ module.exports = async (ctx) => {
const rootUrl = 'https://bioone.org';
const currentUrl = `${rootUrl}/journals/${journal}/current`;
const response = await got({
method: 'get',
url: currentUrl,
const response = await got(currentUrl, {
https: {
rejectUnauthorized: false,
},
});
const $ = cheerio.load(response.data);
let items = $('.TOCLineItemBoldText')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
.toArray()
.map((item) => {
item = $(item).parent();
@ -29,9 +30,10 @@ module.exports = async (ctx) => {
items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const detailResponse = await got(item.link, {
https: {
rejectUnauthorized: false,
},
});
const content = cheerio.load(detailResponse.data);
@ -51,7 +53,8 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: `${response.data.match(/'journalpaper', '(.*)'\)\\" class=\\"/)[1]} - BioOne`,
title: `${$('.panel-body .row a').first().text()} - BioOne`,
description: $('.panel-body .row text').first().text(),
link: currentUrl,
item: items,
};