UNPKG

rsshub

Version:
45 lines (43 loc) 2.01 kB
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/njxzc/utils/index.ts async function getNoticeList(ctx, url, host, titleSelector, dateSelector, contentSelector, listSelector) { const response = await ofetch_default(url); if (!response) return []; const $ = load(response); const list = $(listSelector).toArray().map((item) => { item = $(item); return { title: item.find(titleSelector).attr("title"), link: host + item.find(titleSelector).attr("href"), pubDate: timezone(parseDate(item.find(dateSelector).text(), "YYYY-MM-DD"), 8) }; }); return await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const response$1 = await ofetch_default(item.link); if (!response$1 || response$1.status >= 300 && response$1.status < 400) return { ...item, description: "该通知无法直接预览,请点击原文链接↑查看" }; const $$1 = load(response$1); if ($$1(".wp_error_msg").length > 0) item.description = "您当前ip并非校内地址,该信息仅允许校内地址访问"; else if ($$1(".wp_pdf_player").length > 0) item.description = "该通知无法直接预览,请点击原文链接↑查看"; else { const $content = load($$1(contentSelector.content).html()); $content("a").each(function() { const a = $$1(this); const href = a.attr("href"); if (href && !href.startsWith("http")) a.attr("href", new URL(href, host).href); }); item.description = $content.html(); item.title = $$1(contentSelector.title).text(); item.pubDate = timezone(parseDate($$1(contentSelector.date).text().replace("编辑:", "").replace("发布日期:", "").replace("发布时间:", ""), "YYYY-MM-DD"), 8); } return item; }))); } //#endregion export { getNoticeList as t };