fix(route): 太原师范路由修复 (#10410)

* fix router tynu.

* refactor: migrate to v2
This commit is contained in:
2PoL
2022-08-07 01:37:51 +08:00
committed by GitHub
parent 81b466a36f
commit acc04845c8
7 changed files with 62 additions and 29 deletions
+3 -1
View File
@@ -2461,7 +2461,9 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
## 太原师范学院
<Route author="2PoL" example="/tynu" path="/tynu" />
### 通知公告
<Route author="2PoL" example="/tynu" path="/tynu" rssbud="1" radar="1"/>
## 天津大学
+1 -1
View File
@@ -762,7 +762,7 @@ router.get('/upc/jsj/:type?', lazyloadRouteHandler('./routes/universities/upc/js
// router.get('/ncwu/notice', lazyloadRouteHandler('./routes/universities/ncwu/notice'));
// 太原师范学院
router.get('/tynu', lazyloadRouteHandler('./routes/universities/tynu/tynu'));
// router.get('/tynu', lazyloadRouteHandler('./routes/universities/tynu/tynu'));
// 中北大学
router.get('/nuc/:type', lazyloadRouteHandler('./routes/universities/nuc/index'));
-27
View File
@@ -1,27 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'http://www.tynu.edu.cn/index/xyxw.htm';
const response = await got.get(link);
const $ = cheerio.load(response.data);
const list = $('.winstyle197529 a[class="c197529"]');
ctx.state.data = {
title: '太原师范学院校园新闻',
link,
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.text(),
description: item.text(),
link: item.attr('href'),
};
})
.get(),
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/': ['2PoL'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'tynu.edu.cn': {
_name: '太原师范学院',
'.': [
{
title: '通知公告',
docs: 'https://docs.rsshub.app/university.html#tai-yuan-shi-fan-xue-yuan',
source: ['/index/tzgg.htm', '/index.htm', '/'],
target: '/tynu',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/', require('./tynu'));
};
+39
View File
@@ -0,0 +1,39 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'http://www.tynu.edu.cn';
module.exports = async (ctx) => {
const link = `${baseUrl}/index/tzgg.htm`;
const response = await got(link);
const data = response.data;
const $ = cheerio.load(data);
const list = $('.news_content_list')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('h3').text(),
link: new URL(item.find($('a')).attr('href'), baseUrl).href,
pubDate: parseDate(item.find('.content_list_time').text(), 'YYYYMM-DD'),
};
});
await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = cheerio.load(response.data);
item.description = $('#vsb_content').html() + ($('.content ul').not('.btm-cate').html() || '');
return item;
})
)
);
ctx.state.data = {
title: '太原师范学院通知公告',
link,
item: list,
};
};