* refactor: fix all get * fix(utils/common-config): charset case compare * Revert "fix(utils/common-config): charset case compare" This reverts commit 3c1880f2fad53ad2cafddcee7741390fd46fa3d2. * fix: nga * fix: notateslaapp * fix: ps * fix: xjtu * fix: enforce error on restricted syntax for get calls * fix: eslint * fix: more eslint
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { load } from 'cheerio';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import timezone from '@/utils/timezone';
|
|
|
|
export const route: Route = {
|
|
path: '/cg/:caty?',
|
|
categories: ['university'],
|
|
example: '/cas/cg/cgzhld',
|
|
parameters: { caty: '分类,见下表,默认为工作动态' },
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: false,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['www.cas.cn/cg/:caty?'],
|
|
},
|
|
],
|
|
name: '成果转化',
|
|
maintainers: ['nczitzk'],
|
|
handler,
|
|
description: `| 工作动态 | 科技成果转移转化亮点工作 |
|
|
| -------- | ------------------------ |
|
|
| zh | cgzhld |`,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const caty = ctx.req.param('caty') || 'zh';
|
|
|
|
const rootUrl = 'https://www.cas.cn';
|
|
const currentUrl = `${rootUrl}/cg/${caty}/`;
|
|
const response = await got({
|
|
method: 'get',
|
|
url: currentUrl,
|
|
});
|
|
|
|
const $ = load(response.data);
|
|
const list = $('#content li')
|
|
.not('.gl_line')
|
|
.slice(0, 15)
|
|
.toArray()
|
|
.map((item) => {
|
|
item = $(item);
|
|
const a = item.find('a');
|
|
return {
|
|
title: a.text(),
|
|
link: `${rootUrl}/cg/${caty}${a.attr('href').replace('.', '')}`,
|
|
};
|
|
});
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got({
|
|
method: 'get',
|
|
url: item.link,
|
|
});
|
|
const content = load(detailResponse.data);
|
|
|
|
item.description = content('.TRS_Editor').html();
|
|
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), 8);
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
title: $('title').text().replace('----', ' - '),
|
|
link: currentUrl,
|
|
item: items,
|
|
};
|
|
}
|