diff --git a/lib/v2/gxmzu/lib.js b/lib/v2/gxmzu/lib.js new file mode 100644 index 000000000..6f1d3a720 --- /dev/null +++ b/lib/v2/gxmzu/lib.js @@ -0,0 +1,70 @@ +// 导入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) => + // 使用缓存 + 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 1bbd4f056..708f47441 100644 --- a/lib/v2/gxmzu/maintainer.js +++ b/lib/v2/gxmzu/maintainer.js @@ -1,4 +1,5 @@ module.exports = { '/aitzgg': ['real-jiakai'], + '/libzxxx': ['real-jiakai'], '/yjszsgg': ['real-jiakai'], }; diff --git a/lib/v2/gxmzu/radar.js b/lib/v2/gxmzu/radar.js index 2669a9be8..03896845a 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 0ceba1b11..92d00fd6f 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('/libzxxx', require('./lib')); router.get('/yjszsgg', require('./yjs')); }; diff --git a/website/docs/routes/university.md b/website/docs/routes/university.md index f3db65573..e620ad212 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}