* fix(route): remove next() from mesalab route * refactor: migrate to v2 http://www.sim.cas.cn/xwzx2016/xshd2016/ is dead ---------
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
const timezone = require('@/utils/timezone');
|
|
|
|
module.exports = async (ctx) => {
|
|
ctx.params.caty = ctx.params.caty || 'zh';
|
|
|
|
const rootUrl = 'https://www.cas.cn';
|
|
const currentUrl = `${rootUrl}/cg/${ctx.params.caty}/`;
|
|
const response = await got({
|
|
method: 'get',
|
|
url: currentUrl,
|
|
});
|
|
|
|
const $ = cheerio.load(response.data);
|
|
const list = $('#content li')
|
|
.not('.gl_line')
|
|
.slice(0, 15)
|
|
.map((_, item) => {
|
|
item = $(item);
|
|
const a = item.find('a');
|
|
return {
|
|
title: a.text(),
|
|
link: `${rootUrl}/cg/${ctx.params.caty}${a.attr('href').replace('.', '')}`,
|
|
};
|
|
})
|
|
.get();
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got({
|
|
method: 'get',
|
|
url: item.link,
|
|
});
|
|
const content = cheerio.load(detailResponse.data);
|
|
|
|
item.description = content('.TRS_Editor').html();
|
|
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), 8);
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: $('title').text().replace('----', ' - '),
|
|
link: currentUrl,
|
|
item: items,
|
|
};
|
|
};
|