UNPKG

rsshub

Version:
42 lines (41 loc) 1.6 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 { load } from "cheerio"; //#region lib/routes/ctei/news.ts const route = { path: "/news/:id?", categories: ["new-media"], example: "/ctei/news/bwzq", parameters: { id: "分类 id,可在分类页的 URL 中找到,默认为本网专区" }, name: "资讯", maintainers: ["nczitzk"], description: `| 要闻 | 国内 | 国际 | 企业 | 品牌 | 外贸 | 政策 | 科技 | 流行 | 服装 | 家纺 | | ------ | -------- | -------- | ------- | ----- | ----- | ------ | ---------- | ------- | ------- | ------- | | newsyw | domestic | internal | company | brand | trade | policy | Technology | fashion | apparel | hometex |`, handler }; async function handler(ctx) { const { id = "bwzq" } = ctx.req.param(); const currentUrl = `http://news.ctei.cn/${id}`; const $ = load(await rofetch(currentUrl)); const list = $(".news_text ul li a").toArray().map((item) => { const $item = $(item); return { title: $item.text(), link: `${currentUrl}${$item.attr("href").replace(/\./, "")}` }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { item.description = load(await rofetch(item.link))(".TRS_Editor").html(); item.pubDate = parseDate(item.link.match(/\/t(\d{8})_\d+\.htm/)[1], "YYYYMMDD"); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };