UNPKG

rsshub

Version:
43 lines (42 loc) 1.53 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { t as getPlaywrightPage } from "./playwright-Dd_brOFk.mjs"; import { load } from "cheerio"; //#region lib/routes/yzu/utils.ts const fetchList = async (link, limit) => { const { page, destroy } = await getPlaywrightPage(link, { onBeforeLoad: async (page) => { await page.route("**/*", (route) => ["document", "script"].includes(route.request().resourceType()) ? route.continue() : route.abort()); }, gotoConfig: { waitUntil: "networkidle" } }); const cookie = (await page.context().cookies()).map((c) => `${c.name}=${c.value}`).join("; "); const response = await page.content(); await destroy(); const $ = load(response); const list = $(".list01 li").toArray().slice(0, limit).map((item) => { const $item = $(item); const a = $item.find("a"); return { title: a.attr("title"), link: new URL(a.attr("href"), link).href, date: $item.find("span").text() }; }); return Promise.all(list.map((info) => cache_default.tryGet(info.link, async () => { const $detail = load(await rofetch(info.link, { headers: { Cookie: cookie, Referer: link } })); return { title: info.title, link: info.link, description: $detail(".v_news_content").html()?.trim(), pubDate: timezone(parseDate(info.date), 8) }; }))); }; //#endregion export { fetchList as t };