rsshub
Version:
Make RSS Great Again!
51 lines (50 loc) • 1.61 kB
JavaScript
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/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 response = await rofetch(link);
const $ = load(response);
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 detailResponse = await rofetch(item.link);
const $ = load(detailResponse);
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 };