mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-01 01:28:08 +08:00
* 增加大数据专家委员会和中国人工智能学会新闻 * 修复问题 * fix: add docs for `caai` fix: maintainer does not with match with router * fix: add docs for `ccf/tfbd` fix: use raw output for `art-template` fix: standardise use of `got` not using `got()` in one place and `got.get()` in another place * refactor: migrate to v2 ---------
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const category = ctx.params.category || 'Media_list';
|
|
|
|
const rootUrl = 'https://www.ccf.org.cn';
|
|
const currentUrl = `${rootUrl}/${category}/`;
|
|
const response = await got(currentUrl);
|
|
|
|
const $ = cheerio.load(response.data);
|
|
|
|
const list = $('.tit a')
|
|
.toArray()
|
|
.map((item) => {
|
|
item = $(item);
|
|
return {
|
|
title: item.text(),
|
|
link: `${rootUrl}${item.attr('href')}`,
|
|
};
|
|
});
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got(item.link);
|
|
const content = cheerio.load(detailResponse.data);
|
|
|
|
content('.new_info .num').remove();
|
|
|
|
item.description = content('.txt').html();
|
|
item.pubDate = parseDate(content('.new_info span').text());
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: $('title').text(),
|
|
link: currentUrl,
|
|
item: items,
|
|
};
|
|
};
|