Files
RSSHub/lib/v2/hrbeu/gx/card.js
T
Derek c07c960957 fix: restore /hrbeu/ugs/news.js (#11224)
* fix: restore /heu/ugs/news.js

* Update lib/v2/heu/ugs/news.js

* Update lib/v2/heu/ugs/news.js

* Update lib/v2/heu/ugs/news.js

* feat(require): update require

* refactor: mise fixes

* rename namespace to hrbeu
- hrbeu.edu.cn is the primary domain name as it's where the contact us mail hosted on

* increase code readability
- use template literals over .concat()
- use .includes() to check the existence of sth

* remove fake publish time

* remove duplicated title in description

* fix: fetch article from wechat mp

* fix: codeql
2022-11-09 22:31:19 +08:00

43 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const rootUrl = 'http://news.hrbeu.edu.cn';
module.exports = async (ctx) => {
const column = ctx.params.column;
const id = ctx.params.id || '';
let toUrl;
if (id !== '') {
toUrl = `${rootUrl}/${column}/${id}.htm`;
} else {
toUrl = `${rootUrl}/${column}.htm`;
}
const response = await got(toUrl, {
headers: {
Referer: rootUrl,
},
});
const $ = cheerio.load(response.data);
const bigTitle = $('div.list-left-tt')
.text()
.replace(/[ ]|[\r\n]/g, '');
const card = $('li.clearfix')
.map((_, item) => ({
title: $(item).find('div.list-right-tt').text(),
pubDate: parseDate($(item).find('.news-date-li').text(), 'DDYYYY-MM'),
link: $(item).find('a').attr('href'),
description: $(item).find('div.list-right-p').text(),
}))
.get();
ctx.state.data = {
title: '工学-' + bigTitle,
link: toUrl,
item: card,
};
};