UNPKG

rsshub

Version:
68 lines (67 loc) 2.42 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/cqu/youth.ts const route = { path: "/youth/:category", categories: ["university"], example: "/cqu/youth/tzdt", parameters: { category: "分类名" }, features: { requirePuppeteer: true, antiCrawler: true }, name: "校团委", maintainers: ["Hagb"], handler, description: `| 通知动态 | 院系风采 | 信息公示 | 文件转载 | | -------- | -------- | -------- | -------- | | tzdt | yxfc | xxgs | wjzz |` }; async function handler(ctx) { const { category } = ctx.req.param(); const url = `https://youth.cqu.edu.cn/index/${category}.htm`; const { page, destroy } = await getPlaywrightPage(url, { 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 links = $(".nwes_list a[target=_blank]").toArray().map((item) => ({ title: item.attribs.title, link: new URL(item.attribs.href, url).href })); const items = await Promise.all(links.map(({ title, link }) => cache_default.tryGet(link, async () => { const $detail = load(await rofetch(link, { headers: { Cookie: cookie, Referer: url } })); const newsContent = $detail("form[name=_newscontent_fromname]"); const [dateText, authorText] = newsContent.find("div[align=center]").text().split(/\u{A0}+/u, 2); const newsText = newsContent.find("div[class=v_news_content]"); const attedText = newsText.parent().nextAll().filter("ul[style=\"list-style-type:none;\"]"); return { title, link, pubDate: timezone(parseDate(dateText), 8), author: authorText?.startsWith("拟稿人:") ? authorText.slice(4) : void 0, description: newsText.html() + $detail.html(attedText) }; }))); return { title: $("title").text(), link: url, item: items }; } //#endregion export { route };