UNPKG

rsshub

Version:
73 lines (72 loc) 3.25 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 { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/hkej/index.tsx const route = { path: "/:category?", categories: ["traditional-media"], example: "/hkej/index", parameters: { category: "分類,預設為全部新聞" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.hkej.com/instantnews/:category", "www.hkej.com/instantnews"] }], name: "即時新聞", maintainers: ["TonyRL"], handler, url: "hkej.com/", description: `| index | stock | hongkong | property | china | international | current | market | announcement | hkex | | -------- | -------- | -------- | -------- | -------- | ------------- | -------- | -------- | ------------ | ---------- | | 全部新闻 | 港股直擊 | 香港財經 | 地產新聞 | 中國財經 | 國際財經 | 時事脈搏 | 即巿股評 | 重要通告 | 港交所通告 |` }; async function handler(ctx) { const category = ctx.req.param("category") ?? "index"; const baseUrl = "https://www.hkej.com"; const link = `${baseUrl}/instantnews${category === "index" ? "" : `/${category}`}`; const response = await rofetch.raw(link); const cookies = response.headers.getSetCookie().map((item) => item.split(";", 1)[0]).join(";"); const $ = load(response._data); const list = $("h3 a, h4 a").toArray().map((item) => { const $item = $(item); return { title: $item.text(), link: baseUrl + $item.attr("href").slice(0, $item.attr("href").lastIndexOf("/")) }; }); const renderDesc = (pics, desc) => renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [pics.map((pic) => /* @__PURE__ */ jsxs("figure", { children: [/* @__PURE__ */ jsx("img", { src: pic.href, alt: pic.title }), /* @__PURE__ */ jsx("figcaption", { children: pic.title })] })), raw(desc ?? "")] })); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load(await rofetch(item.link, { headers: { cookie: cookies } })); const articleImg = (content("div.hkej_detail_thumb_2014 td a").length ? content("div.hkej_detail_thumb_2014 td a") : content("div.thumb td a")).toArray().map((e) => { const $e = content(e); return { href: $e.attr("href"), title: $e.attr("title") }; }); const pubDate = content("script[type=\"application/ld+json\"]:contains(\"NewsArticle\")").text().match(/"datePublished": ?"?([^",]+)/)?.[1]; item.category = [...new Set(content("p.info span.cate a, #related-articles-wrapper a font").toArray().map((e) => content(e).text()).filter(Boolean))]; item.description = renderDesc(articleImg, content("div#article-content").html()); item.pubDate = pubDate ? parseDate(pubDate) : void 0; return item; }))); return { title: $("head title").text(), link, item: items, language: "zh-HK" }; } //#endregion export { route };