From 1c876c293e05ea4440ed456e768c21326ae4825a Mon Sep 17 00:00:00 2001 From: Jaya Date: Fri, 22 Sep 2023 08:59:38 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B9=BF?= =?UTF-8?q?=E8=A5=BF=E6=B0=91=E5=A4=A7=E5=9B=BE=E4=B9=A6=E9=A6=86RSS?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/gxmzu/lib.js | 71 +++++++++++++++++++++++++++++++ lib/v2/gxmzu/maintainer.js | 1 + lib/v2/gxmzu/router.js | 1 + website/docs/routes/university.md | 4 ++ 4 files changed, 77 insertions(+) create mode 100644 lib/v2/gxmzu/lib.js diff --git a/lib/v2/gxmzu/lib.js b/lib/v2/gxmzu/lib.js new file mode 100644 index 00000000000000..3ed56840f4514e --- /dev/null +++ b/lib/v2/gxmzu/lib.js @@ -0,0 +1,71 @@ +// 导入got库,该库用来请求网页数据 +const got = require('@/utils/got'); +// 导入cheerio库,该库用来解析网页数据 +const cheerio = require('cheerio'); +// 导入parseDate函数,该函数用于日期处理 +const { parseDate } = require('@/utils/parse-date'); +// 导入timezone库,该库用于时区处理 +const timezone = require('@/utils/timezone'); + +// 广西民大的url链接 +const url = 'https://library.gxmzu.edu.cn/news/news_list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1010'; +// 广西民大图书馆网址 +const host = 'https://library.gxmzu.edu.cn'; + +module.exports = async (ctx) => { + // 发起Http请求,获取网页数据 + const response = await got(url); + + // 解析网页数据 + const $ = cheerio.load(response.data); + + // 通知公告的items的标题、url链接、发布日期 + const list = $('#newslist ul li') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').text(), + link: new URL(item.find('a').attr('href'), host).href, + pubDate: timezone(parseDate(item.find('span').text(), 'YYYY-MM-DD'), +8), + }; + }); + + // 使用缓存 + const out = await Promise.all( + list.map((item) => + // Using cache + ctx.cache.tryGet(item.link, async () => { + // 排除非本站点的外链 + if (item.link && !item.link.startsWith('https://library.gxmzu.edu.cn')) { + item.description = '该通知无法直接预览,请点击原文链接↑查看'; + return item; + } + + // 爬取全文 + const response = await got(item.link); + + // 检查重定向 + if (response.redirectUrls && response.redirectUrls.length > 0) { + item.link = response.redirectUrls[0]; + item.description = '该通知无法直接预览,请点击原文链接↑查看'; + } else { + const $ = cheerio.load(response.data); + item.title = $('h2').text(); + item.description = $('.v_news_content').html(); + } + return item; + }) + ) + ); + + // 生成RSS源 + ctx.state.data = { + // 项目标题 + title: '广西民族大学图书馆 -- 最新消息', + // 项目链接 + link: url, + // items的内容 + item: out, + }; +}; diff --git a/lib/v2/gxmzu/maintainer.js b/lib/v2/gxmzu/maintainer.js index 1bbd4f056f0c1d..f8310b2d389472 100644 --- a/lib/v2/gxmzu/maintainer.js +++ b/lib/v2/gxmzu/maintainer.js @@ -1,4 +1,5 @@ module.exports = { '/aitzgg': ['real-jiakai'], '/yjszsgg': ['real-jiakai'], + '/libzxxx': ['real-jiakai'], }; diff --git a/lib/v2/gxmzu/router.js b/lib/v2/gxmzu/router.js index 0ceba1b1140a36..73d3027889e5f0 100644 --- a/lib/v2/gxmzu/router.js +++ b/lib/v2/gxmzu/router.js @@ -1,4 +1,5 @@ module.exports = (router) => { router.get('/aitzgg', require('./ai')); router.get('/yjszsgg', require('./yjs')); + router.get('/libzxxx', require('./lib')); }; diff --git a/website/docs/routes/university.md b/website/docs/routes/university.md index f3db65573e6ea0..e620ad212dad42 100644 --- a/website/docs/routes/university.md +++ b/website/docs/routes/university.md @@ -1315,6 +1315,10 @@ Note:[Source website](https://ece.umass.edu/seminar) may be empty when there's +### 图书馆最新消息 {#guang-xi-min-zu-da-xue-tu-shu-guan-zui-xin-xiao-xi} + + + ## 广州大学 {#guang-zhou-da-xue} ### 研究生院招生动态 {#guang-zhou-da-xue-yan-jiu-sheng-yuan-zhao-sheng-dong-tai} From 81ae381ea0c8f67316d05cacd7b8f7edc6c65edd Mon Sep 17 00:00:00 2001 From: Jaya Date: Fri, 22 Sep 2023 10:40:57 +0000 Subject: [PATCH 2/3] fix: fix the router order && add library radar --- lib/v2/gxmzu/lib.js | 3 +-- lib/v2/gxmzu/maintainer.js | 2 +- lib/v2/gxmzu/radar.js | 8 ++++++++ lib/v2/gxmzu/router.js | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/v2/gxmzu/lib.js b/lib/v2/gxmzu/lib.js index 3ed56840f4514e..4681cfed0876e5 100644 --- a/lib/v2/gxmzu/lib.js +++ b/lib/v2/gxmzu/lib.js @@ -31,10 +31,9 @@ module.exports = async (ctx) => { }; }); - // 使用缓存 const out = await Promise.all( list.map((item) => - // Using cache + // 使用缓存 ctx.cache.tryGet(item.link, async () => { // 排除非本站点的外链 if (item.link && !item.link.startsWith('https://library.gxmzu.edu.cn')) { diff --git a/lib/v2/gxmzu/maintainer.js b/lib/v2/gxmzu/maintainer.js index f8310b2d389472..708f474418fb71 100644 --- a/lib/v2/gxmzu/maintainer.js +++ b/lib/v2/gxmzu/maintainer.js @@ -1,5 +1,5 @@ module.exports = { '/aitzgg': ['real-jiakai'], - '/yjszsgg': ['real-jiakai'], '/libzxxx': ['real-jiakai'], + '/yjszsgg': ['real-jiakai'], }; diff --git a/lib/v2/gxmzu/radar.js b/lib/v2/gxmzu/radar.js index 2669a9be8b0fca..03896845a0bca2 100644 --- a/lib/v2/gxmzu/radar.js +++ b/lib/v2/gxmzu/radar.js @@ -9,6 +9,14 @@ module.exports = { target: '/gxmzu/aitzgg', }, ], + library: [ + { + title: '图书馆最新消息', + docs: 'https://docs.rsshub.app/routes/unversity#guang-xi-min-zu-da-xue-tu-shu-guan-zui-xin-xiao-xi', + source: ['/news/news_list.jsp', '/'], + target: '/gxmzu/libzxxx', + }, + ], yjs: [ { title: '研究生院招生公告', diff --git a/lib/v2/gxmzu/router.js b/lib/v2/gxmzu/router.js index 73d3027889e5f0..92d00fd6fbed66 100644 --- a/lib/v2/gxmzu/router.js +++ b/lib/v2/gxmzu/router.js @@ -1,5 +1,5 @@ module.exports = (router) => { router.get('/aitzgg', require('./ai')); - router.get('/yjszsgg', require('./yjs')); router.get('/libzxxx', require('./lib')); + router.get('/yjszsgg', require('./yjs')); }; From 0aecd10c47c21121eda84eb1bf7b1052937bf486 Mon Sep 17 00:00:00 2001 From: Jaya Date: Sat, 23 Sep 2023 08:11:41 +0800 Subject: [PATCH 3/3] Update lib/v2/gxmzu/lib.js Co-authored-by: Tony --- lib/v2/gxmzu/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v2/gxmzu/lib.js b/lib/v2/gxmzu/lib.js index 4681cfed0876e5..6f1d3a7205d7cf 100644 --- a/lib/v2/gxmzu/lib.js +++ b/lib/v2/gxmzu/lib.js @@ -36,7 +36,7 @@ module.exports = async (ctx) => { // 使用缓存 ctx.cache.tryGet(item.link, async () => { // 排除非本站点的外链 - if (item.link && !item.link.startsWith('https://library.gxmzu.edu.cn')) { + if (item.link && !item.link.startsWith('https://library.gxmzu.edu.cn/')) { item.description = '该通知无法直接预览,请点击原文链接↑查看'; return item; }