UNPKG

rsshub

Version:
54 lines (52 loc) 1.97 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { r as getSubPath } from "./common-utils-vrWQFAEk.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/yangtzeu/dongke.ts const route = { path: "/dongke/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 10; const rootUrl = "https://dongke.yangtzeu.edu.cn"; const currentUrl = new URL(`${getSubPath(ctx).replace(/^\/dongke/, "") || "/yqzl/xyxw"}.htm`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = $("ul.list-item li a").slice(0, limit).toArray().map((item) => { item = $(item); return { title: item.text(), link: new URL(item.prop("href"), rootUrl).href }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); item.title = content("title").text(); item.description = content("div.v_news_content").html(); item.category = content("meta[name=\"keywords\"]").prop("content").split(","); item.pubDate = timezone(parseDate(content("p.content-info").text().match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)[1]), 8); return item; }))); return { item: items, title: $("title").text(), link: currentUrl, language: "zh-cn", image: new URL($("#head-img a img").prop("src"), rootUrl).href, author: "长江大学动物科学学院" }; } //#endregion export { route };