Files
RSSHub/lib/v2/gxmzu/utils/index.js
T
Jaya 8a76f8743b feat: 添加广西民族大学RSS支持 && fix: 修复南京晓庄学院RSS日期格式 (#12285)
* feat: add gxmzu utils

* fix: test01

* fix: try01

* fix: fix njxzc homepage tzgg date

* docs: add gxmzu rss docs support

* feat: finish gxmzu rss building

* fix: fix njxzc radar's docs

* fix: fix docs/university

* change gxmzu location in docs/university.md

* change gxmzu location in docs/university.md again

* a secomd attempt to change gxmzu location in docs/university.md

* fix: a third attempt to change gxmzu location in docs/university.md

* Update lib/v2/gxmzu/utils/index.js

* Update lib/v2/gxmzu/maintainer.js

---------
2023-04-13 00:01:08 +08:00

56 lines
2.3 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
async function getNoticeList(ctx, url, host, titleSelector, dateSelector, contentSelector) {
const response = await got({ url, https: { rejectUnauthorized: false } });
const $ = cheerio.load(response.data);
const list = $(`tr[height=20]`)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find(titleSelector).attr('title'),
link: new URL(item.find(titleSelector).attr('href'), host).href,
pubDate: timezone(parseDate(item.find(dateSelector).text().trim(), 'YYYY-MM-DD'), +8),
};
});
const out = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (item.link.includes('.jsp')) {
item.description = '该通知无法直接预览,请点击原文链接↑查看';
} else {
const response = await got({ url: item.link, https: { rejectUnauthorized: false } });
if (response.redirectUrls.length) {
item.link = response.redirectUrls[0];
item.description = '该通知无法直接预览,请点击原文链接↑查看';
} else {
const $ = cheerio.load(response.data);
item.title = $(contentSelector.title).text();
const hasEmbeddedPDFScript = $('script:contains("showVsbpdfIframe")').length > 0;
if (hasEmbeddedPDFScript) {
item.description = '该通知无法直接预览,请点击原文链接↑查看';
} else {
item.description = $(contentSelector.content).html();
}
const preDate = $(contentSelector.date).text().replace(/年|月/g, '-').replace(/日/g, '');
item.pubDate = timezone(parseDate(preDate), +8);
}
}
return item;
})
)
);
return out;
}
module.exports = {
getNoticeList,
};