UNPKG

rsshub

Version:
146 lines (144 loc) 5.43 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { n as parseRelativeDate, 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 art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; import { CookieJar } from "tough-cookie"; //#region lib/routes/hkej/index.ts init_esm_shims(); const cookieJar = new CookieJar(); const categories = { index: { name: "", link: "/instantnews/", title: "即時香港中國 國際金融 股市經濟新聞", description: "全天候即時港股、香港財經、國際金融和經濟新聞、中國經濟新聞資訊和分析" }, stock: { name: "港股直擊", link: "/instantnews/stock", title: "即時香港股市 股份板塊 攻略分析", description: "全天候即時港股追蹤和直擊分析,股份異動、大行報告、沽空、速評" }, hongkong: { name: "香港財經", link: "/instantnews/hongkong", title: "即時香港經濟 中港經濟融合追蹤分析", description: "香港經濟和焦點行業 中港融合和商機的分析" }, china: { name: "中國財經", link: "/instantnews/china", title: "即時中國經濟 國策焦點 中港融合追蹤分析", description: "香港經濟和焦點行業 中港融合和商機的分析" }, international: { name: "國際財經", link: "/instantnews/international", title: "即時國際財經 股市匯市 央行政策", description: "國際財經 金融股市 央行政策的新聞和分析" }, property: { name: "地產新聞", link: "/property/news", title: "地產投資", description: "即時地產新聞, 新盤資訊, 樓市分析, 藍籌屋苑數據及室內設計鑑賞" }, current: { name: "時事脈搏", link: "/instantnews/current", title: "即時香港中國 國際金融 股市經濟新聞", description: "全天候即時香港股市、金融、經濟新聞資訊和分析,致力與讀者一起剖釋香港、關注兩岸、放眼全球政經格局" } }; 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: ["hkej.com/"] }], name: "即时新闻", maintainers: ["TonyRL"], handler, url: "hkej.com/", description: `| index | stock | hongkong | china | international | property | current | | -------- | -------- | -------- | -------- | ------------- | -------- | -------- | | 全部新闻 | 港股直击 | 香港财经 | 中国财经 | 国际财经 | 地产新闻 | 时事脉搏 |` }; async function handler(ctx) { const cat = categories[ctx.req.param("category") ?? "index"]; const baseUrl = "https://www2.hkej.com"; const $ = load((await got_default({ method: "get", url: baseUrl + cat.link, headers: { Referer: baseUrl }, cookieJar })).data); const list = $("h3.in_news_u_t a, h4.hkej_hl-news_topic_2014 a, div.hkej_toc_listingAll_news2_2014 h3 a, div.hkej_toc_cat_top_detail h3 a, div.allNews div.news h1 a, div#div_listingAll div.news2 h3 a").toArray().map((item) => { item = $(item); return { title: item.text().trim(), link: baseUrl + item.attr("href").slice(0, item.attr("href").lastIndexOf("/")) }; }); const renderArticleImg = (pics) => art(path.join(__dirname, "templates/articleImg-cbd9e08e.art"), { pics }); const renderDesc = (pics, desc) => art(path.join(__dirname, "templates/description-d7fb5ed6.art"), { pics: renderArticleImg(pics), desc }); const items = await Promise.all(list && list.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link, headers: { Referer: cat.link }, cookieJar })).data); content("#ad_popup").remove(); content("[class^=ad-]").remove(); content("[id^=ad-]").remove(); content("[id^=div-gpt-ad-]").remove(); content(".hkej_sub_ex_article_nonsubscriber_ad_2014").remove(); 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) => { e = $(e); return { href: e.attr("href"), title: e.attr("title") }; }); const pubDate = content("p.info span.date").text().trim(); item.category = content("p.info span.cate a").toArray().map((e) => content(e).text().trim()); item.description = renderDesc(articleImg, content("div#article-content").html()); item.pubDate = timezone(/(今|昨)/.test(pubDate) ? parseRelativeDate(pubDate) : parseDate(pubDate, "YYYY M D"), 8); return item; }))); const ret = { title: `信報網站 - ${cat.title} - 信報網站 hkej.com`, link: baseUrl + cat.link, description: `信報網站(www.hkej.com)即時新聞${cat.name},提供${cat.description}。`, item: items, language: "zh-hk" }; ctx.set("json", { ...ret, cookieJar }); return ret; } //#endregion export { route };