mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-16 16:44:53 +08:00
* 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 Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/gxmzu/maintainer.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * feat: 添加南京中医药大学研究生院博士招生RSS支持 && 添加南京鼓楼医院员工版教育培训RSS支持 * fix: fix njglyy/radar docs typos * Update lib/v2/njucm/radar.js * fix: remove rejectUnauthorized option * Update lib/v2/njucm/radar.js ---------
48 lines
1.7 KiB
JavaScript
48 lines
1.7 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, listSelector, titleSelector, contentSelector) {
|
|
const response = await got(url);
|
|
const $ = cheerio.load(response.data);
|
|
|
|
const list = $(listSelector)
|
|
.toArray()
|
|
.map((item) => {
|
|
item = $(item);
|
|
return {
|
|
title: item.find(titleSelector).attr('title'),
|
|
link: host + item.find(titleSelector).attr('href'),
|
|
};
|
|
});
|
|
|
|
const out = await Promise.all(
|
|
list.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const response = await got(item.link);
|
|
if (response.redirectUrls.length) {
|
|
item.link = response.redirectUrls[0];
|
|
item.description = '该通知无法直接预览,请点击原文链接↑查看';
|
|
} else {
|
|
const $ = cheerio.load(response.data);
|
|
item.title = $(contentSelector.title).text();
|
|
item.description = $(contentSelector.content)
|
|
.html()
|
|
.replace(/src="\//g, `src="${new URL('.', host).href}`)
|
|
.replace(/href="\//g, `href="${new URL('.', host).href}`)
|
|
.trim();
|
|
item.pubDate = timezone(parseDate($(contentSelector.date).text()), +8);
|
|
}
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
return out;
|
|
}
|
|
|
|
module.exports = {
|
|
getNoticeList,
|
|
};
|