UNPKG

rsshub

Version:
67 lines (66 loc) 2.45 kB
import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as got_default } from "./got-BDnf4rdT.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/chinanews/index.ts const rootUrl = "https://www.chinanews.com.cn"; const route = { path: "/", categories: ["traditional-media"], example: "/chinanews", radar: [{ source: ["chinanews.com.cn/"], target: "" }], name: "最新", maintainers: ["yuxinliu-alex"], handler, url: "chinanews.com.cn/" }; async function handler(ctx) { const language = "zh-CN"; const currentUrl = `${rootUrl}/scroll-news/news1.html`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); const limit = ctx.req.query("limit"); const list = $("a", ".dd_bt").toArray().map((item) => ({ link: rootUrl + $(item).attr("href"), title: $(item).text() })).slice(0, limit ? Number.parseInt(limit) : 50); return { title: "中国新闻网", link: currentUrl, description: "中国新闻网(简称“中新网”),由中国新闻社主办,为中央重点新闻网站。", language, item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content(".adInContent").remove(); if (content("div.content_desc").length > 0) { item.description = content("div.content_desc").html(); item.author = content("a.source").text(); const info = content("p", ".left").text().trim().slice(5).split(" "); item.author = info[2].trim(); item.pubDate = timezone(parseDate(info[0] + info[1], "YYYY年MM月DD日HH:mm"), 8); } else if (content("div.t3").length > 0) { item.description = content("div.t3").html(); const info = content("div[style=\"text-align:right;font-size:12px;\"]").text().slice(5).split(" "); item.author = info[2]; item.pubDate = timezone(parseDate(info[0] + info[1], "YYYY-MM-DDHH:mm"), 8); } else { item.description = content("div.left_zw").html(); const info = content("div.left-t").contents().filter((_, el) => el.type === "text").text().split(" "); item.pubDate = timezone(parseDate(info[0], "YYYY年MM月DD日 HH:mm"), 8); item.author = info[1] + content("a.source").text(); } return item; }))) }; } //#endregion export { route };