* refactor: fix scut namespace * refactor: fix gzhu namespace * refactor: fix scnu namespace * refactor: fix hust namespace * refactor: fix ccnu namespace * refactor: fix sustech namespace * refactor: fix szu namespace remove `/szuyjs` since it's a duplicate of `/szu/yz/:type?` * refactor: fix tongji namespace * refactor: fix ocu namespace * refactor: fix upc namespace * refactor: fix ucas namespace * refactor: fix cas namespace * refactor: fix cau namespace * refactor: remove `/cucyjs` since `/cuc/yz` existed well before that * refactor: fix bit namespace * refactor: fix **undocumented** scau namespace * fix: typo * fix: code scan
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const baseUrl = 'https://newshub.sustech.edu.cn';
|
|
const link = `${baseUrl}/news`;
|
|
const response = await got({
|
|
method: 'get',
|
|
url: link,
|
|
});
|
|
|
|
const data = response.data;
|
|
|
|
const $ = cheerio.load(data);
|
|
|
|
const list = $('.m-newslist ul li');
|
|
|
|
ctx.state.data = {
|
|
title: '南方科技大学新闻网-中文',
|
|
link,
|
|
item:
|
|
list &&
|
|
list.toArray().map((item) => {
|
|
item = $(item);
|
|
const itemPicUrl = item
|
|
.find('.u-pic div')
|
|
.attr('style')
|
|
.match(/url\('(.+?)'\)/)[1];
|
|
const itemPubdate = item.find('.mobi').text();
|
|
return {
|
|
pubDate: parseDate(itemPubdate, 'YYYY-MM-DD'),
|
|
title: item.find('.f-clamp').text(),
|
|
description: `<img src="${baseUrl}${itemPicUrl}"><br>${item.find('.f-clamp4').text()}`,
|
|
link: `${baseUrl}${item.find('a').attr('href')}`,
|
|
};
|
|
}),
|
|
};
|
|
};
|