Files
RSSHub/lib/v2/nuist/library/lib.js
T
Ethan ShenandTony 28c61bf84a fix(route): 南京信息工程大学研究生院学科建设处 (#10464)
* fix(route): 南京信息工程大学研究生院学科建设处

* fix: deprecated url resolve

* update lib/v2/nuist/yjs.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix: typo
2022-08-16 00:01:36 +08:00

44 lines
1.2 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseTitle = '南京信息工程大学图书馆通知';
const baseUrl = 'https://lib.nuist.edu.cn';
module.exports = async (ctx) => {
const link = baseUrl + '/index/tzgg.htm';
const response = await got(link);
const $ = cheerio.load(response.data);
const list = $('.list2 li')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
category: '通知',
link: new URL(item.find('a').attr('href'), link).href,
};
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = cheerio.load(response.data);
item.description = $('#vsb_content').html();
item.pubDate = parseDate($('.date').find('span').eq(0).text(), 'YYYY年MM月DD日');
return item;
})
)
);
ctx.state.data = {
title: baseTitle,
link,
item: items,
};
};