Files
RSSHub/lib/v2/njust/cwc.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

40 lines
1.2 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([
['tzgg', { title: '南京理工大学财务处 -- 通知公告', id: '/12432' }],
['bslc', { title: '南京理工大学财务处 -- 办事流程', id: '/1382' }],
]);
const host = 'https://cwc.njust.edu.cn';
module.exports = async (ctx) => {
const type = ctx.params.type ?? 'tzgg';
const info = map.get(type);
if (!info) {
throw 'invalid type';
}
const id = info.id;
const siteUrl = host + id + '/list.htm';
const html = await getContent(siteUrl, true);
const $ = cheerio.load(html);
const list = $('ul.news_list').find('li');
ctx.state.data = {
title: info.title,
link: siteUrl,
item:
list &&
list
.map((index, item) => ({
title: $(item).find('a').attr('title').trim(),
pubDate: timezone(parseDate($(item).find('span.news_meta').text(), 'YYYY-MM-DD'), +8),
link: $(item).find('a').attr('href'),
}))
.get(),
};
};