Files
RSSHub/lib/v2/scut/seie/news_center.js
Tony 8699b4c9d3 fix(route): fix namespace mess from #4283 (#12353)
* refactor: fix scut namespace

* refactor: fix gzhu namespace

* refactor: fix scnu namespace

* refactor: fix hust namespace

* refactor: fix ccnu namespace

* refactor: fix sustech namespace

* refactor: fix szu namespace

remove `/szuyjs` since it's a duplicate of `/szu/yz/:type?`

* refactor: fix tongji namespace

* refactor: fix ocu namespace

* refactor: fix upc namespace

* refactor: fix ucas namespace

* refactor: fix cas namespace

* refactor: fix cau namespace

* refactor: remove `/cucyjs` since `/cuc/yz` existed well before that

* refactor: fix bit namespace

* refactor: fix **undocumented** scau namespace

* fix: typo

* fix: code scan
2023-04-20 09:32:13 +08:00

53 lines
2.0 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://www2.scut.edu.cn';
const url = `${rootUrl}/ee/16285/list.htm`;
const response = await got(url);
const $ = cheerio.load(response.data);
const list = $('.news_ul li');
const articleList = list.toArray().map((item) => {
item = $(item);
const titleElement = item.find('.news_title a');
return {
title: titleElement.attr('title'),
link: titleElement.attr('href'),
pubDate: parseDate(item.find('.news_meta').text(), 'YYYY-MM-DD'),
};
});
const items = await Promise.all(
articleList.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(`${rootUrl}${item.link}`);
const content = cheerio.load(detailResponse.data);
content('.wp_articlecontent *').each((_, child) => {
const childElem = content(child);
childElem.removeAttr('style');
childElem.removeAttr('lang');
childElem.removeAttr('original-src');
childElem.removeAttr('sudyfile-attr');
childElem.removeAttr('data-layer');
if ((!childElem.text().replace('\n', '').trim().length && !childElem.has('img')) || childElem.attr('name') === '_GoBack' || childElem.is('style')) {
childElem.remove();
}
});
const contentHTML = content('.wp_articlecontent').html();
item.description = contentHTML.replace(/^(<br>)+|(<br>)+$/g, '').trim();
return item;
})
)
);
ctx.state.data = {
title: '华南理工大学电子与信息学院 - 新闻速递',
link: url,
item: items,
};
};