feat: 添加广西民族大学图书馆最新消息RSS的支持 (#13364)
* feat: 添加广西民大图书馆RSS支持 * fix: fix the router order && add library radar * Update lib/v2/gxmzu/lib.js ---------
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
'/aitzgg': ['real-jiakai'],
|
||||
'/libzxxx': ['real-jiakai'],
|
||||
'/yjszsgg': ['real-jiakai'],
|
||||
};
|
||||
|
||||
@@ -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: '研究生院招生公告',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/aitzgg', require('./ai'));
|
||||
router.get('/libzxxx', require('./lib'));
|
||||
router.get('/yjszsgg', require('./yjs'));
|
||||
};
|
||||
|
||||
@@ -1315,6 +1315,10 @@ Note:[Source website](https://ece.umass.edu/seminar) may be empty when there's
|
||||
|
||||
<Route author="real-jiakai" example="/gxmzu/aitzgg" path="/gxmzu/aitzgg" radar="1" />
|
||||
|
||||
### 图书馆最新消息 {#guang-xi-min-zu-da-xue-tu-shu-guan-zui-xin-xiao-xi}
|
||||
|
||||
<Route author="real-jiakai" example="/gxmzu/libzxxx" path="/gxmzu/libzxxx" radar="1" />
|
||||
|
||||
## 广州大学 {#guang-zhou-da-xue}
|
||||
|
||||
### 研究生院招生动态 {#guang-zhou-da-xue-yan-jiu-sheng-yuan-zhao-sheng-dong-tai}
|
||||
|
||||
Reference in New Issue
Block a user