rsshub
Version:
Make RSS Great Again!
86 lines (84 loc) • 2.91 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 { i as rootUrl, n as apiTopicUrl, r as processItems } from "./util-DdepA4pY.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/readhub/index.ts
init_esm_shims();
const route = {
path: "/:category?",
categories: ["new-media"],
example: "/readhub",
parameters: { category: "分类,见下表,默认为热门话题" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "分类",
maintainers: [
"WhiteWorld",
"nczitzk",
"Fatpandac"
],
handler,
description: `| 热门话题 | 科技动态 | 医疗产业 | 财经快讯 |
| -------- | -------- | -------- | ------------------ |
| | news | medical | financial\_express |`
};
async function handler(ctx) {
const { category = "" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30;
const currentUrl = new URL(category ?? "", rootUrl).href;
const { data: currentResponse } = await got_default(currentUrl);
const { data: response } = await got_default(apiTopicUrl, { searchParams: {
type: currentResponse.match(/\[\\"type\\",\\"(\d+)\\",\\"d\\"]/)?.[1] ?? "1",
page: 1,
size: limit
} });
let items = response.data.items.slice(0, limit).map((item) => ({
title: item.title,
link: item.url ?? new URL(`topic/${item.uid}`, rootUrl).href,
description: art(path.join(__dirname, "templates/description-71daa88b.art"), {
description: item.summary,
news: item.newsAggList,
timeline: item.timeline
}),
author: item.siteNameDisplay,
category: [...item.entityList.map((c) => c.name) ?? [], ...item.tagList.map((c) => c.name) ?? []],
guid: item.uid,
pubDate: parseDate(item.publishDate)
}));
items = await processItems(items, cache_default.tryGet);
const $ = load(currentResponse);
const author = $("meta[property=\"og:site_name\"]").prop("content");
const subtitle = $(`a[data-path="/${category}"]`).text();
const image = $("link[rel=\"preload\"][as=\"image\"]").prop("href");
const icon = $("meta[property=\"og:image\"]").prop("content");
return {
item: items,
title: `${author} - ${subtitle}`,
link: currentUrl,
description: $("meta[property=\"og:description\"]").prop("content"),
language: "zh",
image,
icon,
logo: icon,
subtitle,
author,
allowEmpty: true
};
}
//#endregion
export { route };