Files
RSSHub/lib/routes/ecnu/comm.ts
T
千代有希=andFrozenStarrrr 81b0d3ef9d feat(route): add 12 more route of ECNU's insititutes (#20582)
* fix(route): fix wrong title of /ecnu/bksy

Co-authored-by: FrozenStarrrr <frozenstars@qq.com>

* feat(route): add ECNU Software Engineering Insitute notices route

* fix(route): modify wrong radar target

* add School of Computer Science and Technology ECNU notices route

* add School of data science and engineering notices route

* add School of Comm. & Elec. Engineering notices route

* add School of Geospace A.I. Engineering ECNU notices route

* add ECNU faculty of Edu. notices route

* add ECNU faculty of Earth Sci. notices route

* add ECNU Meng Xiancheng notices route

* add ECNU Guanghua notices route

* fix(route): add empty line at the end of files.

* add department of history ECNU notices route

* add department of Philo. ECNU notices route

* fix(route): add maintainer of /ecnu/bksy

* fix(route): delete unnecessary try-catch statment, modified incorrect url, fix image url.

* fix(route): fix unnecessary try-catch, description, condition and wrond url

* fix(route): fix image display

* fix(route): fix problems in bksy.ts

* feat(route): add ecnu/pharm

* feat(route): add art insititute of ECNU

* feat(route): add route of school of Stat. ECNU

* feat(route): add route of school of Phy. & Elec., ECNU

* feat(route): add route of school of Chem. & Mol., ECNU

* feat(route): add route of school of Eco. & Envir., ECNU

* feat(route): add route of school of Comm., ECNU

* feat(route): add route of school of International Chinese Studies, ECNU

* feat(route): add route of school of Psy. & cognitive Sci., ECNU

* feat(route): add route of college of Phy. Edu. & health , ECNU

* feat(route): add route of college of public management, ECNU

* feat(route): add route of college of Marxismus, ECNU

* fix(routes): fix incorrect time display and remove unnecessary codes

* fix(foute): format the code

---------

Co-authored-by: FrozenStarrrr <frozenstars@qq.com>
2025-12-03 21:37:24 +08:00

60 lines
2.0 KiB
TypeScript

import { load } from 'cheerio';
import type { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export const route: Route = {
path: '/comm',
categories: ['university'],
example: '/ecnu/comm',
radar: [
{
source: ['comm.ecnu.edu.cn'],
target: '/comm',
},
],
name: '传播学院通知公告',
maintainers: ['FrozenStarrrr', 'ChiyoYuki', 'ECNU-minus'],
handler: async () => {
const baseUrl = 'https://comm.ecnu.edu.cn/';
const response = await got(`${baseUrl}41511/list.htm`);
const $ = load(response.data);
const links = $('ul.news_list.list2 > li')
.toArray()
.map((el) => ({
pubDate: timezone(parseDate($(el).find('.news_meta').text()), +8),
link: new URL($(el).find('a').attr('href'), baseUrl).toString(),
title: $(el).find('a').text(),
}));
const items = await Promise.all(
links.map((item) =>
cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
const $ = load(data);
const $read = $('div.wp_articlecontent');
$read.find('img[src], a[href]').each((i, el) => {
const $el = $(el);
const attr = el.tagName === 'img' ? 'src' : 'href';
const val = $el.attr(attr);
if (val) {
$el.attr(attr, new URL(val, baseUrl).toString());
}
});
item.description = $read.html()?.trim();
return item;
})
)
);
return {
title: '传播学院通知公告',
link: 'https://comm.ecnu.edu.cn/41511/list.htm',
item: items,
};
},
};