From 1c9131ee463faae627ebb10d2d17c36d62dda8e0 Mon Sep 17 00:00:00 2001 From: yesRabbit Date: Sat, 27 Nov 2021 16:47:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=B8=A9=E5=B7=9E=E5=A4=A7?= =?UTF-8?q?=E5=AD=A6=E6=96=B0=E9=97=BB=E8=B7=AF=E7=94=B1=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20(#8443)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tony --- docs/university.md | 8 ++- lib/router.js | 3 -- lib/routes/universities/wzu/news.js | 25 --------- lib/v2/wzu/maintainer.js | 3 ++ lib/v2/wzu/news.js | 84 +++++++++++++++++++++++++++++ lib/v2/wzu/radar.js | 11 ++++ lib/v2/wzu/router.js | 3 ++ 7 files changed, 108 insertions(+), 29 deletions(-) delete mode 100644 lib/routes/universities/wzu/news.js create mode 100644 lib/v2/wzu/maintainer.js create mode 100644 lib/v2/wzu/news.js create mode 100644 lib/v2/wzu/radar.js create mode 100644 lib/v2/wzu/router.js diff --git a/docs/university.md b/docs/university.md index 19022727e..f95cc6efe 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1929,7 +1929,13 @@ type 列表: ### 新闻 - + + +| 温大新闻 | 媒体温大 | 学术温大 | 通知公告 | 招标信息 | 学术公告 | +| :------: | :------: | :------: | :------: | :------: | :------: | +| 0 | 1 | 2 | 3 | 4 | 5 | + + ## 温州商学院 diff --git a/lib/router.js b/lib/router.js index 41a952a36..ba6427815 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4165,9 +4165,6 @@ router.get('/harvard/health/blog', lazyloadRouteHandler('./routes/universities/h // yuzu emulator router.get('/yuzu-emu/entry', lazyloadRouteHandler('./routes/yuzu-emu/entry')); -// 温州大学 -router.get('/wzu/news', lazyloadRouteHandler('./routes/universities/wzu/news')); - // Resources - The Partnership on AI router.get('/partnershiponai/resources', lazyloadRouteHandler('./routes/partnershiponai/resources')); diff --git a/lib/routes/universities/wzu/news.js b/lib/routes/universities/wzu/news.js deleted file mode 100644 index 4348b1fba..000000000 --- a/lib/routes/universities/wzu/news.js +++ /dev/null @@ -1,25 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); - -module.exports = async (ctx) => { - const link = 'http://www.wzu.edu.cn/index/wdxw.htm'; - const response = await got.get(link); - const $ = cheerio.load(response.data); - const list = $('#News-sidebar-b-nav').find('li'); - - ctx.state.data = { - title: '温大新闻', - link, - description: '温州大学', - item: - list && - list - .map((index, item) => { - item = $(item); - const a1 = item.find('li a'); - return { title: a1.attr('title'), description: a1.attr('title'), pubDate: parseDate(item.find('li samp').text(), 'YYYY-MM-DD'), link: a1.attr('href') }; - }) - .get(), - }; -}; diff --git a/lib/v2/wzu/maintainer.js b/lib/v2/wzu/maintainer.js new file mode 100644 index 000000000..4449153e7 --- /dev/null +++ b/lib/v2/wzu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:type?': ['Chandler-Lu'], +}; diff --git a/lib/v2/wzu/news.js b/lib/v2/wzu/news.js new file mode 100644 index 000000000..c77b4664e --- /dev/null +++ b/lib/v2/wzu/news.js @@ -0,0 +1,84 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { URL } = require('url'); +const { parseDate } = require('@/utils/parse-date'); + +/* 新闻列表 +温大新闻 http://www.wzu.edu.cn/index/wdxw.htm +媒体温大 http://www.wzu.edu.cn/index/mtwd.htm +学术温大 http://www.wzu.edu.cn/index/xswd.htm +通知公告 http://www.wzu.edu.cn/index/tzgg.htm +招标信息 http://www.wzu.edu.cn/index/zbxx.htm +学术公告 http://www.wzu.edu.cn/index/xsgg.htm +*/ + +const baseUrl = 'http://www.wzu.edu.cn/index/'; + +const newsType = { + wdxw: '温大新闻', + mtwd: '媒体温大', + xswd: '学术温大', + tzgg: '通知公告', + zbxx: '招标信息', + xsgg: '学术公告', +}; + +/** + * @description: 抓取文章内容 + * @param {*} link + * @return {*} description + */ +async function load(link) { + let videoUrl = ''; + // 请求文章页面 + const newsResp = await got.get(link); + // 加载文章内容 + const $ = cheerio.load(newsResp.data, { decodeEntities: false }); + // 图片相对链接处理 + $('img').attr('src', (n, v) => new URL(v, baseUrl).href); + // 视频相对链接处理,替换原有播放方法 showVsbVideo + $('.vsbcontent_video').each(function () { + const u1 = $(this).find('script').attr('vurl'); + videoUrl = new URL(u1, baseUrl).href; + return $(this) + .html('') + .html(); + }); + // 返回解析的结果 + return $('div[id^=vsb_content]').html(); +} + +module.exports = async (ctx) => { + // 获取路由 Tag + const routeTag = parseInt(ctx.params.type) || 0; + // 设定新闻标题及 Url + const newsArr = Object.entries(newsType); + const [k1, newsTitle] = newsArr[routeTag]; + const newsLink = new URL(k1 + '.htm', baseUrl).href; + + const response = await got.get(newsLink); + const $ = cheerio.load(response.data); + const list = $('#News-sidebar-b-nav').find('li'); + + ctx.state.data = { + title: newsTitle, + link: newsLink, + description: '温州大学' + ' - ' + newsTitle, + item: + list && + list + .map(async (item) => { + const $ = cheerio.load(list[item]); + const $a1 = $('li>a'); + const $originUrl = $a1.attr('href'); + const $itemUrl = new URL($originUrl, baseUrl).href; + return { + title: $a1.attr('title'), + description: await ctx.cache.tryGet($itemUrl, () => load($itemUrl)), + pubDate: parseDate($('li>samp').text(), 'YYYY-MM-DD'), + link: $itemUrl, + }; + }) + .get(), + }; +}; diff --git a/lib/v2/wzu/radar.js b/lib/v2/wzu/radar.js new file mode 100644 index 000000000..e7f139f0f --- /dev/null +++ b/lib/v2/wzu/radar.js @@ -0,0 +1,11 @@ +module.exports = { + 'wzu.edu.cn': { + _name: '温州大学', + '.': [ + { + title: '温州大学 - 主站新闻', + docs: 'https://docs.rsshub.app/university.html#wen-zhou-da-xue', + }, + ], + }, +}; diff --git a/lib/v2/wzu/router.js b/lib/v2/wzu/router.js new file mode 100644 index 000000000..c36fd4f1c --- /dev/null +++ b/lib/v2/wzu/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:type?', require('./news')); +};