UNPKG

rsshub

Version:
118 lines (102 loc) 4 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 { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; import iconv from "iconv-lite"; //#region lib/routes/cs/index.ts const decodeBufferByCharset = (buffer) => { const encoding = /charset="?'?gb/i.test(buffer.toString()) ? "gbk" : "utf-8"; return iconv.decode(buffer, encoding); }; const route = { path: "/:category{.+}?", name: "栏目", parameters: { category: "分类,见下表,默认为首页" }, maintainers: ["nczitzk"], description: `| 要闻 | 公司 | 市场 | 基金 | | ---- | ---- | ---- | ---- | | xwzx | ssgs | gppd | tzjj | | 科创 | 产经 | 期货 | 海外 | | ---- | ------ | -------- | ------ | | 5g | cj2020 | zzqh2020 | hw2020 | <details> <summary>更多栏目</summary> #### 要闻 | 财经要闻 | 观点评论 | 民生消费 | | -------- | -------- | --------- | | xwzx/hg | xwzx/jr | xwzx/msxf | #### 公司 | 公司要闻 | 公司深度 | 公司巡礼 | | --------- | --------- | --------- | | ssgs/gsxw | ssgs/gssd | ssgs/gsxl | #### 市场 | A 股市场 | 港股资讯 | 债市研究 | 海外报道 | 期货报道 | | --------- | --------- | --------- | --------- | --------- | | gppd/gsyj | gppd/ggzx | gppd/zqxw | gppd/hwbd | gppd/qhbd | #### 基金 | 基金动态 | 基金视点 | 基金持仓 | 私募基金 | 基民学苑 | | --------- | --------- | --------- | --------- | --------- | | tzjj/jjdt | tzjj/jjks | tzjj/jjcs | tzjj/smjj | tzjj/tjdh | #### 机构 | 券商 | 银行 | 保险 | | ---- | ---- | ---- | | qs | yh | bx | #### 其他 | 中证快讯 7x24 | IPO 鉴真 | 公司能见度 | | ------------- | -------- | ---------- | | sylm/jsbd | yc/ipojz | yc/gsnjd | </details>`, handler }; async function handler(ctx) { const { category = "xwzx" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30; const rootUrl = "https://www.cs.com.cn"; const currentUrl = new URL(category.endsWith("/") ? category : `${category}/`, rootUrl).href; const { data: response } = await got_default(currentUrl, { responseType: "buffer" }); const $ = load(decodeBufferByCharset(response)); let items = $("ul.ch_type3_list li a").slice(0, limit).toArray().map((item) => { item = $(item); return { title: item.find("h3").text().trim(), link: new URL(item.prop("href"), currentUrl).href, pubDate: timezone(parseDate(item.find("em").text()), 8) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const { data: detailResponse } = await got_default(item.link, { responseType: "buffer" }); const content = load(decodeBufferByCharset(detailResponse)); item.title = content("article.cont_article header h1").text().trim(); item.description = content("article.cont_article section").html(); item.author = content("div.artc_info em").text().trim(); item.category = content("div.artc_route div a").slice(1).toArray().map((c) => content(c).prop("title") ?? content(c).text()); item.pubDate = timezone(parseDate(content(".time").prop("datetime")), 8); } catch {} return item; }))); const title = $("title").text(); const image = new URL($("div.logo_cs a img").prop("src"), currentUrl).href; const icon = new URL("favicon.ico", rootUrl).href; return { item: items, title, link: currentUrl, description: $("meta[name=\"Description\"]").prop("content"), language: $("html").prop("lang"), image, icon, logo: icon, subtitle: $("meta[name=\"Keywords\"]").prop("content"), author: title.split("-").pop().trim() }; } //#endregion export { route };