refactor: migrate hitsz to v2 (#11851)

This commit is contained in:
Tony
2023-02-14 03:36:19 +08:00
committed by GitHub
parent 8283cd260a
commit fb1154449e
6 changed files with 38 additions and 21 deletions
+5 -5
View File
@@ -1274,13 +1274,13 @@ category 列表:
## 哈尔滨工业大学(深圳)
### 哈尔滨工业大学(深圳) - 新闻中心
### 新闻中心
<Route author="xandery-geek" example="/hitsz/article/id-74" path="/hitsz/article/:category?" :paramsDesc="['分类名,默认为通知公告']" >
<Route author="xandery-geek" example="/hitsz/article/id-74" path="/hitsz/article/:category?" :paramsDesc="['分类名,默认为校园动态']" radar="1">
| 校区要闻 | 媒体报道 | 通知公告 | 综合新闻 | 校园动态 | 讲座论坛 | 热点专题 |
| ------ | ----- | ----- | ----- | ----- | ----- | ----- |
| id-116 | id-80 | id-74 | id-75 | id-77 | id-78 | id-79 |
| 校区要闻 | 媒体报道 | 综合新闻 | 校园动态 | 讲座论坛 | 热点专题 | 招标信息 | 重要关注 |
| ------ | ----- | ----- | ----- | ----- | ----- | ----- | ------ |
| id-116 | id-80 | id-75 | id-77 | id-78 | id-79 | id-81 | id-124 |
</Route>
+1 -1
View File
@@ -531,7 +531,7 @@ router.get('/hhu/libNewsc', lazyloadRouteHandler('./routes/universities/hhu/libN
// router.get('/hit/today/:category', lazyloadRouteHandler('./routes/universities/hit/today'));
// 哈尔滨工业大学(深圳)
router.get('/hitsz/article/:category?', lazyloadRouteHandler('./routes/universities/hitsz/article'));
// router.get('/hitsz/article/:category?', lazyloadRouteHandler('./routes/universities/hitsz/article'));
// 哈尔滨工业大学(威海)
// router.get('/hitwh/today', lazyloadRouteHandler('./routes/universities/hitwh/today'));
@@ -1,34 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const host = 'http://www.hitsz.edu.cn';
const category = ctx.params.category || 'id-74';
const host = 'https://www.hitsz.edu.cn';
const category = ctx.params.category ?? 'id-77';
const link = `${host}/article/${category}.html`;
const response = await got.get(`${host}/article/${category}.html`);
const response = await got(link);
const $ = cheerio.load(response.data);
const category_name = $('div.title_page').text().trim();
const lists = $('.mainside_news ul li')
.map((_, el) => ({
.toArray()
.map((el) => ({
title: $('a', el).text().trim(),
link: `${host}${$('a', el).attr('href')}`,
pubDate: new Date($('span[class=date]', el).text()).toUTCString(),
}))
.get();
pubDate: timezone(parseDate($('span[class=date]', el).text()), 8),
}));
const items = await Promise.all(
lists.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got.get(item.link);
const $ = cheerio.load(response.data);
item.description =
$('div.detail').html() &&
$('div.detail')
.html()
.replace(/src="\//g, `src="${new URL('.', host).toString()}"`)
.replace(/href="\//g, `href="${new URL('.', host).toString()}"`)
.trim();
item.description = $('div.edittext').html().trim();
item.pubDate = timezone(parseDate($('.item').first().text().replace('发布时间:', '')), 8);
return item;
})
)
@@ -36,7 +34,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: '哈尔滨工业大学(深圳)-' + category_name,
link: `${host}/article/${category}.html`,
link,
description: '哈尔滨工业大学(深圳)-' + category_name,
item: items,
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/article/:category?': ['xandery-geek'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'hitsz.edu.cn': {
_name: '哈尔滨工业大学(深圳)',
'.': [
{
title: '新闻中心',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-ye-da-xue-shen-zhen',
source: ['/article/:category?', '/subject/:category?'],
target: (params) => `/hitsz/article/${params.category.replace('.html', '')}`,
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/article/:category?', require('./article'));
};