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

42 lines
1.3 KiB
JavaScript

const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const { getContent } = require('./utils');
const host = 'https://gs.njust.edu.cn';
module.exports = async (ctx) => {
const type = ctx.params.type ?? 'sytzgg_4568';
const id = '/' + type;
const siteUrl = host + id + '/list.htm';
const html = await getContent(siteUrl);
const $ = cheerio.load(html);
const title = '南京理工大学研究生院 -- ' + $('title').text();
const list = $('ul.news_ul').find('li');
const items = await Promise.all(
list.map(async (index, item) => {
const url = $(item).find('a').attr('href');
let desc = '';
if (url.startsWith('/')) {
const data = await getContent(host + url);
desc = cheerio.load(data)('.wp_articlecontent').html();
}
return {
title: $(item).find('a').attr('title').trim(),
description: desc,
pubDate: timezone(parseDate($(item).find('span').text(), 'YYYY-MM-DD'), +8),
link: url,
};
})
);
ctx.state.data = {
title,
link: siteUrl,
item: items,
};
};