mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): normalize /bwu/news rss output (#7295)
* fix: typo :P * fix: reduce duplication of jQuery selectors * fix: reformat invalid author tag * fix: pubDate use parseDate fix: replace depreciated url.resolve Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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 };
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user