Files
RSSHub/lib/v2/njust/eo.js
Zhiyang Guo ac7b3666d8 fix(route): 南京理工大学 (#9659)
* fix(route): 南京理工大学

* refactor: migrate to v2

* refactor: migrate to v2

* Update yarn.lock

* fix: remove standalone puppeteer extra

* fix(route): minor misc changes

* fix(route): sort routes in alphabetical order

* fix(route): update utils.js
2022-05-03 19:37:58 +08:00

51 lines
1.9 KiB
JavaScript

const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const { getContent } = require('./utils');
const map = new Map([
['16tz', { title: '南京理工大学电光16 -- 通知公告', id: '/_t217/tzgg' }],
['16dt', { title: '南京理工大学电光16 -- 主任寄语', id: '/_t217/zrjy' }],
['17tz', { title: '南京理工大学电光17 -- 年级通知', id: '/_t689/njtz' }],
['17dt', { title: '南京理工大学电光17 -- 每日动态', id: '/_t689/mrdt' }],
['18tz', { title: '南京理工大学电光18 -- 年级通知', id: '/_t900/njtz_10234' }],
['18dt', { title: '南京理工大学电光18 -- 主任寄语', id: '/_t900/zrjy_10251' }],
['19tz', { title: '南京理工大学电光19 -- 通知公告', id: '/_t1163/tzgg_11606' }],
['19dt', { title: '南京理工大学电光19 -- 每日动态', id: '/_t1163/mrdt_11608' }],
]);
const host = 'https://dgxg.njust.edu.cn';
module.exports = async (ctx) => {
const grade = ctx.params.grade ?? '17';
const type = ctx.params.type ?? 'tz';
let info = map.get(grade + type);
if (!info) {
// throw 'invalid type';
info = { title: '', id: '/' + grade + '/' + type };
}
const id = info.id;
const siteUrl = host + id + '/list.htm';
const html = await getContent(siteUrl, true);
const $ = cheerio.load(html);
if (!info.title) {
info.title = $('title').text();
}
const list = $('li.list_item');
ctx.state.data = {
title: info.title,
link: siteUrl,
item:
list &&
list
.map((index, item) => ({
title: $(item).find('a').text().trim(),
pubDate: timezone(parseDate($(item).find('span.Article_PublishDate').text(), 'YYYY-MM-DD'), +8),
link: $(item).find('a').attr('href'),
}))
.get(),
};
};