rsshub
Version:
Make RSS Great Again!
136 lines (133 loc) • 3.76 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import { t as ViewType } from "./types-gOySfSXJ.mjs";
import "./logger-C4avouvV.mjs";
import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs";
import { t as parseDate } from "./parse-date-r5WDWHno.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.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/theblockbeats/index.tsx
const rootUrl = `https://www.theblockbeats.info`;
const apiBase = `https://api.blockbeats.cn`;
const render = (data) => {
const $ = load(renderToString(/* @__PURE__ */ jsx(BlockBeatsDescription, {
image: data.image,
description: data.description
})), null, false);
$("img").each((_, e) => {
const $e = $(e);
const src = $e.attr("src");
$e.attr("src", src?.split("?")[0]);
});
return $.html();
};
const BlockBeatsDescription = ({ image, description }) => /* @__PURE__ */ jsxs(Fragment, { children: [image ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("img", { src: image }), /* @__PURE__ */ jsx("br", {})] }) : null, description ? raw(description) : null] });
const channelMap = {
newsflash: {
title: "快讯",
link: `${rootUrl}/newsflash`,
api: `${apiBase}/v2/newsflash/list`
},
article: {
title: "文章",
link: `${rootUrl}/article`,
api: `${apiBase}/v2/article/list`
}
};
const route = {
path: "/:channel?/:original?",
categories: ["finance"],
view: ViewType.Articles,
example: "/theblockbeats/newsflash",
parameters: {
channel: {
description: "类型",
options: [{
value: "newsflash",
label: "快讯"
}, {
value: "article",
label: "文章"
}],
default: "newsflash"
},
original: {
description: "文章类型,仅 `channel` 为 `article` 时有效",
options: [
{
value: "0",
label: "全部"
},
{
value: "1",
label: "深度"
},
{
value: "2",
label: "精选"
},
{
value: "3",
label: "热点追踪"
}
],
default: "0"
}
},
name: "新闻快讯",
maintainers: [
"Fatpandac",
"jameshih",
"DIYgod"
],
handler,
radar: [{
title: "文章",
source: ["www.theblockbeats.info/article"],
target: "/article"
}, {
title: "快讯",
source: ["www.theblockbeats.info/newsflash"],
target: "/newsflash"
}],
description: `| 快讯 | 文章 |
| :-------: | :-----: |
| newsflash | article |
| 全部 | 深度 | 精选 | 热点追踪 |
| :--: | :--: | :--: | :---: |
| | -2 | 1 | 2 |`
};
async function handler(ctx) {
const { channel = "newsflash", original } = ctx.req.param();
let list = (await ofetch_default(channelMap[channel].api, { query: {
limit: ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20,
original: channel === "article" ? original : void 0
} })).data.list.map((item) => ({
title: item.title,
link: `${rootUrl}/${channel === "newsflash" ? "flash" : "news"}/${item.article_id}`,
description: item.content ?? item.abstract,
pubDate: parseDate(item.add_time, "X"),
author: item.author?.nickname,
category: item.tag_list,
imgUrl: item.img_url
}));
if (channel !== "newsflash") list = await Promise.all(list.map((item) => cache_default.tryGet(`theblockbeats:${item.link}`, async () => {
const $ = load(await ofetch_default(item.link));
item.description = render({
image: item.imgUrl,
description: $("div.news-content").html()
});
return item;
})));
return {
title: `TheBlockBeats - ${channelMap[channel].title}`,
link: channelMap[channel].link,
item: list
};
}
//#endregion
export { route };