Files
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

50 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseTitle = 'NUIST CS(南信大计软院)';
const baseUrl = 'https://scs.nuist.edu.cn';
module.exports = async (ctx) => {
const { category = 'xwkx' } = ctx.params;
const link = `${baseUrl}/${category}/list.htm`;
const response = await got(link);
const $ = cheerio.load(response.data);
const list = $('.newsList ul')
.eq(0)
.find('li')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
link: new URL(item.find('a').attr('href'), baseUrl).href,
pubDate: parseDate(item.find('.newsDate').text()),
};
});
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);
const authorMatch = $('.newsTitleAddDate')
.text()
.match(/发布者:(.*)发布时间/);
item.author = authorMatch ? authorMatch[1].trim() : null;
item.description = $('.newsContent').html();
return item;
})
)
);
ctx.state.data = {
title: baseTitle + ':' + $('head title').text(),
description: $('meta[name=description]').attr('content'),
link,
item: items,
};
};