Files
RSSHub/lib/v2/bit/jwc/utils.js
Tony 8699b4c9d3 fix(route): fix namespace mess from #4283 (#12353)
* 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
2023-04-20 09:32:13 +08:00

50 lines
1.4 KiB
JavaScript
Raw 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 timezone = require('@/utils/timezone');
// 专门定义一个function用于加载文章内容
async function load(item) {
// 异步请求文章
const response = await got(item.link);
// 加载文章内容
const $ = cheerio.load(response.data);
// 提取内容
item.description = $('.gp-article').html();
// 返回解析的结果
return item;
}
const ProcessFeed = (list, caches) => {
const host = 'https://jwc.bit.edu.cn/tzgg/';
return Promise.all(
// 遍历每一篇文章
list.map((item) => {
const $ = cheerio.load(item);
const $title = $('a');
// 还原相对链接为绝对链接
const itemUrl = new URL($title.attr('href'), host).href;
// 列表上提取到的信息
const single = {
title: $title.text(),
link: itemUrl,
author: '教务部',
pubDate: timezone(parseDate($('span').text()), 8),
};
// 使用tryGet方法从缓存获取内容。
// 当缓存中无法获取到链接内容的时候则使用load方法加载文章内容。
return caches.tryGet(single.link, () => load(single));
})
);
};
module.exports = {
ProcessFeed,
};