diff --git a/lib/routes/universities/bwu/news.js b/lib/routes/universities/bwu/news.js index 05a5243634..83df42f24e 100644 --- a/lib/routes/universities/bwu/news.js +++ b/lib/routes/universities/bwu/news.js @@ -4,7 +4,7 @@ const util = require('./utils'); module.exports = async (ctx) => { const title = '通知公告'; - const host = 'http://news.bwu.edu.cn/'; + const host = 'https://news.bwu.edu.cn/'; const path = 'tzgg.htm'; const response = await got({ diff --git a/lib/routes/universities/bwu/utils.js b/lib/routes/universities/bwu/utils.js index 883a6a8792..980f465aeb 100644 --- a/lib/routes/universities/bwu/utils.js +++ b/lib/routes/universities/bwu/utils.js @@ -1,38 +1,35 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const url = require('url'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); // Processing full text async function load(link) { - const responce = await got.get(link); - const $ = cheerio.load(responce.data); - const author = $('div[class=articleAuthor] p span').eq(1).text().slice(5); + const response = await got.get(link); + const $ = cheerio.load(response.data); + const author = $('div[class=articleAuthor] p span').eq(1).text() || 'null'; + const authorName = author.indexOf(':') !== -1 ? author.split(':')[1].trim() : author; + const validAuthor = 'xcb@bwu.edu.cn (' + authorName + ')'; // Extracting text const description = $('div[id^=vsb_content]').html(); return { description, - author, + author: validAuthor, }; } const ProcessFeed = (list, cache) => { - const host = 'http://news.bwu.edu.cn/'; + const host = 'https://news.bwu.edu.cn/'; return Promise.all( list.map(async (item) => { const $ = cheerio.load(item); - const title = $('a').text(); - const link = url.resolve(host, $('a').attr('href')); + const aTag = $('a'); + const title = aTag.text(); + const link = new URL(aTag.attr('href'), host); // Parsing the date - const date = new Date( - $('span[class=rightDate]') - .text() - .match(/\d{4}-\d{2}-\d{2}/) - ); - const timeZone = 8; - const serverOffset = date.getTimezoneOffset() / 60; - const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString(); + const pubDate = timezone(parseDate($('span[class=rightDate]').text(), 'YYYY-MM-DD'), +8); const single = { title, @@ -43,7 +40,7 @@ const ProcessFeed = (list, cache) => { // Try caching const other = await cache.tryGet(link, () => load(link)); // Return article information - return Promise.resolve(Object.assign({}, single, other)); + return { ...single, ...other }; }) ); };