UNPKG

rsshub

Version:
49 lines (48 loc) 1.54 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 { load } from "cheerio"; //#region lib/routes/tpre/news.ts const route = { path: "/news", categories: ["other"], example: "/tpre/news", radar: [{ source: ["www.tpre.cn/news/zxdt.html"] }], name: "中心动态", maintainers: ["kt286"], handler, url: "www.tpre.cn/news/zxdt.html" }; async function handler() { const baseUrl = "https://www.tpre.cn"; const link = `${baseUrl}/news/zxdt.html`; const $ = load(await rofetch(link)); const list = $(".newsLi").toArray().map((item) => { const $item = $(item); const a = $item.find("a.newsTitle"); return { title: a.text(), link: new URL(a.attr("href"), baseUrl).href, pubDate: timezone(parseDate($item.find(".newsTime").text(), "YYYY-MM-DD"), 8) }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const $ = load(await rofetch(item.link)); const content = $(".newsinfo .newsDesc"); const [time, author] = $(".newsinfo .newsTime span").toArray().map((e) => $(e).text()); return { ...item, description: content.html(), pubDate: timezone(parseDate(time.replace("时间:", ""), "YYYY-M-D H:mm:ss"), 8), author: author?.replace("作者:", "") }; }))); return { title: $("head title").text(), link, item: items }; } //#endregion export { route };