UNPKG

rsshub

Version:
49 lines (48 loc) 1.91 kB
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs"; import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { load } from "cheerio"; //#region lib/routes/jou/utils/index.ts const FALLBACK_DESCRIPTION = "该通知无法直接预览,请点击原文链接↑查看"; function parsePubDate(text) { const match = text?.match(/(\d{4})[-/.年]\s*(\d{1,2})[-/.月]\s*(\d{1,2})/); if (!match) return; const [, year, month, day] = match; const time = text?.match(/(\d{1,2}:\d{2}(?::\d{2})?)/)?.[1]; return timezone(parseDate(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}${time ? ` ${time}` : ""}`), 8); } function parseNoticeList($, pageUrl, rowSelector, dateSelector) { return $(rowSelector).toArray().map((el) => { const $row = $(el); const $link = $row.find("a"); const href = $link.attr("href"); if (!href) return null; return { title: $link.attr("title") || $link.text().trim(), link: new URL(href, pageUrl).href, pubDate: parsePubDate($(dateSelector, $row).text()) }; }).filter((item) => item !== null); } async function fetchArticle(item, selectors) { const $ = load(await rofetch(item.link)); if ($("script:contains(\"showVsbpdfIframe\")").length > 0) return { ...item, description: FALLBACK_DESCRIPTION }; const $content = $(selectors.content); const title = $(selectors.title).text().trim(); const pubDate = selectors.date ? parsePubDate($(selectors.date).text()) : void 0; return { ...item, title: title || item.title, pubDate: pubDate ?? item.pubDate, description: $content.html() }; } function resolveArticles(list, selectors) { return Promise.all(list.map((item) => cache_default.tryGet(item.link, () => fetchArticle(item, selectors)))); } //#endregion export { resolveArticles as n, parseNoticeList as t };