Files
RSSHub/lib/v2/ccf/news.js
tudou027 65eaa2a6d9 feat(route): 增加大数据专家委员会和中国人工智能学会新闻 (#11510)
* 增加大数据专家委员会和中国人工智能学会新闻

* 修复问题

* 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

---------
2023-02-28 00:21:26 +08:00

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,
};
};