UNPKG

rsshub

Version:
40 lines (39 loc) 1.35 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.mjs"; import { load } from "cheerio"; //#region lib/routes/lixin/utils.ts async function fetchMain(url, dataElement) { const response = await rofetch(url); const $ = load(response); return { list: $(dataElement).toArray().map((item) => { const $item = $(item); return { href: $item.children("a").attr("href"), publishDate: $item.children("span").text() }; }), title: $("title").text() }; } function fetchDetail(list, baseUrl, contentElement) { return Promise.all(list.map((item) => { const href = item.href.startsWith("http") ? item.href : baseUrl + item.href; return cache_default.tryGet(href, async () => { const response = await rofetch(href); const $ = load(response); let description = $(contentElement).html(); if (!description) description = `无法解析公告, 这可能是因为这是一个外部链接或者文件. 请<a href="${href}">点击查看</a>`; return { title: $("title").text(), link: href, description, pubDate: timezone(parseDate(item.publishDate, "YYYY-MM-DD"), 8) }; }); })); } //#endregion export { fetchMain as n, fetchDetail as t };