mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: add dlmu news feed. (#4280)
This commit is contained in:
@@ -2405,4 +2405,7 @@ router.get('/socialclub/events/:game?', require('./routes/socialclub/events'));
|
||||
// 湖北大学
|
||||
router.get('/hubu/news/:type', require('./routes/universities/hubu/news'));
|
||||
|
||||
// 大连海事大学
|
||||
router.get('/dlmu/news/:type', require('./routes/universities/dlmu/news'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
const got = require('@/utils/got');
|
||||
const iconv = require('iconv-lite');
|
||||
const cheerio = require('cheerio');
|
||||
const resolve_url = require('url').resolve;
|
||||
|
||||
const base_url = 'http://news.dlmu.edu.cn';
|
||||
|
||||
const map = {
|
||||
hdyw: '/hdyw.htm',
|
||||
mthd: '/mthd.htm',
|
||||
zhxw: '/zhxw.htm',
|
||||
yxfc: '/yxfc.htm',
|
||||
hdxb: '/hdxb.htm',
|
||||
llyd: '/llyd.htm',
|
||||
hdjt: '/hdjt.htm',
|
||||
ywhc: '/ywhc.htm',
|
||||
};
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
const link = map.hasOwnProperty(type) ? `${base_url}${map[type]}` : `${base_url}/hdyw.htm`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
responseType: 'buffer',
|
||||
headers: {
|
||||
Referer: base_url,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(iconv.decode(response.data, 'utf-8'));
|
||||
ctx.state.data = {
|
||||
link: base_url,
|
||||
title: '大连海事大学新闻',
|
||||
item: $('.n-Box .n-right .n-pic-box .n-news dl')
|
||||
.slice(0, 10)
|
||||
.map((_, element) => ({
|
||||
link: resolve_url(base_url, $('dd a', element).attr('href')),
|
||||
title: $('dd a', element).text(),
|
||||
description: $('dd p', element).text(),
|
||||
pubDate: new Date(
|
||||
$('i', element)
|
||||
.text()
|
||||
.slice(1, -1)
|
||||
),
|
||||
}))
|
||||
.get(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user