Skip to content

Commit

Permalink
style: auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 10, 2021
1 parent 5bd84ab commit dbf27ec
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions lib/routes/universities/lntu/jwnews.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,45 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');

module.exports = async(ctx) => {
const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm';
const response = await got.get(link);

const $ = cheerio.load(response.data);
const list = $('.tr-ri ul').find('li').get();

const res = await Promise.all(
list.map(async(item) => {
let $ = cheerio.load(item);
// 通过解析后的子项地址
const item_link = url.resolve(link, $('a').attr('href'));

const description = await ctx.cache.tryGet(item_link, async() => {
const result = await got.get(item_link);

$ = cheerio.load(result.data);
// remove style
$('img, div, span, p, table, td, tr').removeAttr('style');
$('style, script').remove();

return $('.v_news_content').html().replace(/(<span[^>]*>|<\/span>)/g, "");
});

const rssitem = {
title: $('title').text().split('-')[0],
description: description,
link: item_link,
author: '辽宁工程技术大学教务处',
};
return Promise.resolve(rssitem);
})
);

ctx.state.data = {
title: '辽宁工程技术大学教务公告',
link: link,
item: res,
};
module.exports = async (ctx) => {
const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm';
const response = await got.get(link);

const $ = cheerio.load(response.data);
const list = $('.tr-ri ul').find('li').get();

const res = await Promise.all(
list.map(async (item) => {
let $ = cheerio.load(item);
// 通过解析后的子项地址
const item_link = url.resolve(link, $('a').attr('href'));

const description = await ctx.cache.tryGet(item_link, async () => {
const result = await got.get(item_link);

$ = cheerio.load(result.data);
// remove style
$('img, div, span, p, table, td, tr').removeAttr('style');
$('style, script').remove();

return $('.v_news_content')
.html()
.replace(/(<span[^>]*>|<\/span>)/g, '');
});

const rssitem = {
title: $('title').text().split('-')[0],
description: description,
link: item_link,
author: '辽宁工程技术大学教务处',
};
return Promise.resolve(rssitem);
})
);

ctx.state.data = {
title: '辽宁工程技术大学教务公告',
link: link,
item: res,
};
};

0 comments on commit dbf27ec

Please sign in to comment.