fix(route): 大学通知/哈尔滨工程大学/水声工程学院 (#13135)

* fix(route): 大学通知/哈尔滨工程大学/水声工程学院

* Update lib/v2/hrbeu/uae/news.js

Thank you, this method is more accurate.

* Update lib/v2/hrbeu/uae/news.js

---------
This commit is contained in:
Derek 2023-08-27 21:36:46 +08:00 committed by GitHub
parent 9cbdf9093c
commit 686df84294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 65 deletions

View File

@ -63,10 +63,10 @@ module.exports = {
],
uae: [
{
title: '水声学院',
title: '水声工程学院',
docs: 'https://docs.rsshub.app/routes/university#ha-er-bin-gong-cheng-da-xue',
source: '/:id/list.htm',
target: '/hrbeu/uae/list/:id',
source: '/:id.htm',
target: '/hrbeu/uae/:id',
},
],
ugs: [

View File

@ -4,7 +4,7 @@ module.exports = function (router) {
router.get('/job/list/:id', require('./job/list'));
router.get('/gx/card/:column/:id?', require('./gx/card'));
router.get('/gx/list/:column/:id?', require('./gx/list'));
router.get('/uae/list/:id', require('./uae/list'));
router.get('/uae/:id', require('./uae/news'));
router.get('/ugs/news/:author?/:category?', require('./ugs/news'));
router.get('/yjsy/list/:id', require('./yjsy/list'));
};

View File

@ -1,57 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { finishArticleItem } = require('@/utils/wechat-mp');
const rootUrl = 'http://uae.hrbeu.edu.cn';
module.exports = async (ctx) => {
const id = ctx.params.id;
const response = await got(`${rootUrl}/${id}/list.htm`, {
headers: {
Referer: rootUrl,
},
});
const $ = cheerio.load(response.data);
const bigTitle = $('h2.column-title').text();
const list = $('a.column-news-item')
.map((_, item) => {
let link = $(item).attr('href');
if (link.includes('page.htm')) {
link = `${rootUrl}${link}`;
}
return {
title: $(item).find('span.column-news-title').text(),
pubDate: parseDate($(item).find('span.column-news-date').text()),
link,
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (item.link.includes('page.htm')) {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
item.description = content('div.wp_articlecontent').html();
item.title = content('h1.arti-title').text();
} else if (new URL(item.link).hostname === 'mp.weixin.qq.com') {
await finishArticleItem(ctx, item);
} else {
item.description = '本文需跳转,请点击标题后阅读';
}
return item;
})
)
);
ctx.state.data = {
title: '水声学院-' + bigTitle,
link: `${rootUrl}/${id}/list.htm`,
item: items,
};
};

66
lib/v2/hrbeu/uae/news.js Normal file
View File

@ -0,0 +1,66 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { finishArticleItem } = require('@/utils/wechat-mp');
module.exports = async (ctx) => {
const id = ctx.params.id.replace(/-/g, '/');
const host = 'http://uae.hrbeu.edu.cn';
const url = `${host}/${id}.htm`;
const response = await got(url, {
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const title = $('h2').text();
const items = $('li.wow.fadeInUp')
.map((_, item) => {
const title = $(item).find('a').attr('title');
let link = $(item).find('a').attr('href');
if (!link.startsWith('http')) {
link = `${host}/${link}`;
}
const pubDate = parseDate(
$(item)
.find('div.date')
.text()
.replace(/(.*)\/(.*)/g, '$2-$1')
);
return {
title,
pubDate,
link,
};
})
.get();
const item = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (new URL(item.link).hostname === 'uae.hrbeu.edu.cn') {
const resp = await got(item.link);
const $1 = cheerio.load(resp.data);
item.description = $1('div.art-body').html();
} else if (new URL(item.link).hostname === 'news.hrbeu.edu.cn') {
const resp = await got(item.link);
const $1 = cheerio.load(resp.data);
item.description = $1('div#print').html();
} else if (new URL(item.link).hostname === 'mp.weixin.qq.com') {
await finishArticleItem(ctx, item);
} else {
item.description = '本文需跳转,请点击标题后阅读';
}
return item;
})
)
);
ctx.state.data = {
title: `水声工程学院 - ${title}`,
link: url,
item,
};
};

View File

@ -1473,11 +1473,11 @@ category 列表:
### 水声工程学院 {#ha-er-bin-gong-cheng-da-xue-shui-sheng-gong-cheng-xue-yuan}
<Route author="Derekmini" example="/hrbeu/uae/list/3751" path="/hrbeu/uae/list/:id" paramsDesc={['栏目编号,由 `URL` 中获取。']} radar="1" rssbud="1">
<Route author="Derekmini" example="/hrbeu/uae/xwdt" path="/hrbeu/uae/:id" paramsDesc={['栏目编号,在 `URL` 中获取如果有多级编号 `/` 替换为 `-`。']} radar="1" rssbud="1">
| 新闻动态 | 通知公告 | 其他 |
| :------: | :------: | :--: |
| 3751 | 3752 | ... |
| 新闻动态 | 通知公告 | 科学研究/科研动态 |
| :------: | :------: | :------------: |
| xwdt | tzgg | kxyj-kydt |
</Route>