diff --git a/lib/radar-rules.js b/lib/radar-rules.js index 08c9fb6b70..d979aaa6a7 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -2799,31 +2799,6 @@ module.exports = { }, ], }, - 'cqwu.net': { - _name: '重庆文理学院', - www: [ - { - title: '通知', - docs: 'https://docs.rsshub.app/university.html#chong-qing-wen-li-xue-yuan', - source: '/:type', - target: (params) => { - if (params.type === 'channel_7721.html') { - return '/cqwu/news/notify'; - } - }, - }, - { - title: '学术活动', - docs: 'https://docs.rsshub.app/university.html#chong-qing-wen-li-xue-yuan', - source: '/:type', - target: (params) => { - if (params.type === 'channel_7722.html') { - return '/cqwu/news/academiceve'; - } - }, - }, - ], - }, 'trakt.tv': { _name: 'Trakt.tv', '.': [ diff --git a/lib/router.js b/lib/router.js index 3fdb9b38cd..ef94d513f3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -720,9 +720,6 @@ router.get('/cqu/youth/:category', lazyloadRouteHandler('./routes/universities/c router.get('/cqu/sci/:category', lazyloadRouteHandler('./routes/universities/cqu/sci/info')); router.get('/cqu/net/:category', lazyloadRouteHandler('./routes/universities/cqu/net/info')); -// 重庆文理学院 -router.get('/cqwu/news/:type?', lazyloadRouteHandler('./routes/universities/cqwu/news')); - // 南京信息工程大学 router.get('/nuist/bulletin/:category?', lazyloadRouteHandler('./routes/universities/nuist/bulletin')); router.get('/nuist/jwc/:category?', lazyloadRouteHandler('./routes/universities/nuist/jwc')); diff --git a/lib/routes/universities/cqwu/news.js b/lib/routes/universities/cqwu/news.js deleted file mode 100644 index e32a01e22c..0000000000 --- a/lib/routes/universities/cqwu/news.js +++ /dev/null @@ -1,39 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url').resolve; - -const host = 'http://www.cqwu.edu.cn'; -const map = { - notify: '/channel_7721.html', - academiceve: '/channel_7722.html', -}; -const titleMap = { - notify: '通知', - academiceve: '学术活动', -}; - -module.exports = async (ctx) => { - const type = ctx.params.type || 'academiceve'; - const link = host + map[type]; - const title = '重文理' + titleMap[type] + '公告'; - const response = await got.get(link); - const $ = cheerio.load(response.data); - const list = $('ul[class="list-unstyled news-uls"]').find('li'); - ctx.state.data = { - title, - link, - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('h4').text(), - description: item.find('p').text(), - pubDate: new Date(item.find('span[class="pull-right nes-date"]').text()).toUTCString(), - link: url(host, item.find('a').attr('href')), - }; - }) - .get(), - }; -}; diff --git a/lib/v2/cqwu/index.js b/lib/v2/cqwu/index.js new file mode 100644 index 0000000000..086b6e6fa4 --- /dev/null +++ b/lib/v2/cqwu/index.js @@ -0,0 +1,46 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +const host = 'http://www.cqwu.net'; +const map = { + notify: '/channel_7721.html', + academiceve: '/channel_7722.html', +}; +const titleMap = { + notify: '通知', + academiceve: '学术活动', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type ?? 'academiceve'; + const link = host + map[type]; + const title = '重文理' + titleMap[type] + '公告'; + const response = await got.get(link); + const $ = cheerio.load(response.data); + const list = $('ul[class="list-unstyled news-uls"]').find('li'); + + const items = await Promise.all( + list.map(async (_, item) => { + const pageUrl = host + $(item).find('a').attr('href'); + const desc = await ctx.cache.tryGet(pageUrl, async () => { + const page = await got.get(pageUrl); + const $ = cheerio.load(page.data); + return $('.news-info').html(); + }); + + return { + title: $(item).find('a').text(), + link: pageUrl, + description: desc, + pubDate: parseDate($(item).find('span').text()), + }; + }) + ); + + ctx.state.data = { + title, + link, + item: items, + }; +}; diff --git a/lib/v2/cqwu/maintainer.js b/lib/v2/cqwu/maintainer.js new file mode 100644 index 0000000000..bf31901cda --- /dev/null +++ b/lib/v2/cqwu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:type?': ['Fatpandac'], +}; diff --git a/lib/v2/cqwu/radar.js b/lib/v2/cqwu/radar.js new file mode 100644 index 0000000000..8a65299b4c --- /dev/null +++ b/lib/v2/cqwu/radar.js @@ -0,0 +1,27 @@ +module.exports = { + 'cqwu.net': { + _name: '重庆文理学院', + www: [ + { + title: '通知', + docs: 'https://docs.rsshub.app/university.html#chong-qing-wen-li-xue-yuan', + source: '/:type', + target: (params) => { + if (params.type === 'channel_7721.html') { + return '/cqwu/news/notify'; + } + }, + }, + { + title: '学术活动', + docs: 'https://docs.rsshub.app/university.html#chong-qing-wen-li-xue-yuan', + source: '/:type', + target: (params) => { + if (params.type === 'channel_7722.html') { + return '/cqwu/news/academiceve'; + } + }, + }, + ], + }, +}; diff --git a/lib/v2/cqwu/router.js b/lib/v2/cqwu/router.js new file mode 100644 index 0000000000..c5f8be7c11 --- /dev/null +++ b/lib/v2/cqwu/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:type?', require('./index')); +};