rsshub
Version:
Make RSS Great Again!
132 lines (129 loc) • 3.43 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/theblockbeats/index.ts
init_esm_shims();
const rootUrl = `https://www.theblockbeats.info`;
const apiBase = `https://api.blockbeats.cn`;
const render = (data) => {
const $ = load(art(path.join(__dirname, "templates/description-ee3da0fe.art"), data), null, false);
$("img").each((_, e) => {
const $e = $(e);
const src = $e.attr("src");
$e.attr("src", src?.split("?")[0]);
});
return $.html();
};
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 };