Files
RSSHub/lib/v2/science/early.js
Tony 90d257789d fix(route): science (#10751)
* fix(route): science

* fix: image
2022-09-10 00:01:51 +08:00

34 lines
941 B
JavaScript

const cheerio = require('cheerio');
const got = require('@/utils/got');
const { baseUrl, fetchDesc, getItem } = require('./utils');
module.exports = async (ctx) => {
const { journal = 'science' } = ctx.params;
const pageUrl = `${baseUrl}/toc/${journal}/0/0`;
const { data: res } = await got(pageUrl, {
headers: {
cookie: 'cookiePolicy=iaccept;',
},
});
const $ = cheerio.load(res);
const list = $('.card-content .card-header')
.toArray()
.map((item) => getItem(item, $));
const browser = await require('@/utils/puppeteer')();
const items = await fetchDesc(list, browser, ctx.cache.tryGet);
await browser.close();
ctx.state.data = {
title: $('head title').text(),
description: $('.body02').text().trim(),
image: `${baseUrl}/apple-touch-icon.png`,
link: pageUrl,
language: 'en-US',
item: items,
};
};