rsshub
Version:
Make RSS Great Again!
113 lines (111 loc) • 4.35 kB
JavaScript
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 { 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 dayjs from "dayjs";
import { load } from "cheerio";
//#region lib/routes/oncc/money18.ts
init_esm_shims();
const sections = {
exp: "新聞總覽",
fov: "全日焦點",
industry: "板塊新聞",
int: "國際金融",
recagent: "大行報告",
ntlgroup: "A股新聞",
pro: "地產新聞",
weainvest: "投資理財",
ipo: "新股IPO",
tech: "科技財情"
};
const route = {
path: "/money18/:id?",
categories: ["traditional-media"],
example: "/oncc/money18/exp",
parameters: { id: "栏目 id,可在对应栏目页 URL 中找到,默认为 exp,即新聞總覽" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "Money18",
maintainers: ["nczitzk"],
handler,
description: `| 新聞總覽 | 全日焦點 | 板塊新聞 | 國際金融 | 大行報告 | A 股新聞 | 地產新聞 | 投資理財 | 新股 IPO | 科技財情 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
| exp | fov | industry | int | recagent | ntlgroup | pro | weainvest | ipo | tech |`
};
async function handler(ctx) {
const id = ctx.req.param("id") ?? "exp";
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 30;
const rootUrl = "https://money18.on.cc";
const currentUrl = `${rootUrl}/finnews/news_${id === "industry" ? "industry.html" : `breaking.html?section=${id}`}`;
const ipoApiUrl = `https://dyn.on.cc/api/asrh/v1/events/names/新股/articles?page=1&limit=${limit}`;
const industryApiUrl = `${rootUrl}/cnt/utf8/content/articleList/sector_list_exp_1.js`;
const toApiUrl = (date) => `${rootUrl}/cnt/utf8/content/${date}/articleList/list_${id}_all.js`;
let apiUrl = id === "ipo" ? ipoApiUrl : id === "industry" ? industryApiUrl : toApiUrl(dayjs().format("YYYYMMDD")), hasArticle = false, items = [], i = 0, response;
while (!hasArticle) try {
response = await got_default({
method: "get",
url: apiUrl
});
hasArticle = true;
} catch (error) {
if (error.code === "ERR_NON_2XX_3XX_RESPONSE") {
hasArticle = false;
apiUrl = toApiUrl(dayjs().subtract(++i, "day").format("YYYYMMDD"));
}
}
if (id === "ipo") items = response.data.articles.map((item) => ({
title: item.title,
author: item.authorname,
link: `${rootUrl}/finnews/content/${id}/${item.articleId}.html`,
description: art(path.join(__dirname, "templates/money18-3f53584c.art"), {
images: item.hasHdPhoto ? [`https://hk.on.cc/hk/bkn${item.hdEnlargeThumbnail}`] : void 0,
description: item.content
}),
pubDate: timezone(parseDate(item.pubDate), 8)
}));
else if (id === "industry") items = response.data.articles.slice(0, limit).map((item) => ({
title: item.title,
author: item.authorname,
link: `${rootUrl}/finnews/content/${id}/${item.articleId}.html`,
category: item.sector.map((s) => s.name),
pubDate: timezone(parseDate(item.pubDate), 8)
}));
else items = response.data.slice(0, limit).map((item) => ({
title: item.title,
author: item.authorname,
link: `${rootUrl}/finnews/content/${id}/${item.articleId}.html`,
pubDate: timezone(parseDate(item.pubDate), 8)
}));
if (id !== "ipo") items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
item.description = art(path.join(__dirname, "templates/money18-3f53584c.art"), {
images: content(".photo img").toArray().map((i$1) => content(i$1).attr("src")),
description: content(".content").html()
});
return item;
})));
return {
title: `東網產經 - ${sections[id]}`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };