rsshub
Version:
Make RSS Great Again!
109 lines (107 loc) • 3.74 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 { load } from "cheerio";
//#region lib/routes/ithome/zt.ts
init_esm_shims();
const handler = async (ctx) => {
const { id = "xijiayi" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 50;
const rootUrl = "https://www.ithome.com";
const currentUrl = new URL(`zt/${id}`, rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
const author = "IT之家";
const language = "zh";
let items = $("div.newsbody").slice(0, limit).toArray().map((item) => {
item = $(item);
const title = item.find("h2").text();
const image$1 = item.find("img").prop("data-original") ?? item.find("img").prop("src");
return {
title,
pubDate: timezone(parseDate(item.find("span.time script").text().match(/'(.*?)'/)), 8),
link: item.find("a").first().prop("href"),
author: item.find("div.editor").contents().first().text(),
image: image$1,
banner: image$1,
language
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const $$ = load(detailResponse);
$$("p.ad-tips, a.topic-bar").remove();
$$("div#paragraph p img").each((_, el) => {
el = $$(el);
const src = el.prop("data-original");
if (src) el.replaceWith(art(path.join(__dirname, "templates/description-463c9506.art"), { images: [{
src,
alt: el.prop("alt")
}] }));
});
const title = $$("h1").text();
const description = $$("div#paragraph").html();
const image$1 = $$("div#paragraph img").first().prop("src");
item.title = title;
item.description = description;
item.pubDate = timezone(parseDate($$("span#pubtime_baidu").text()), 8);
item.category = $$("div.cv a").toArray().map((c) => $$(c).text()).slice(1);
item.author = $$("span#author_baidu").contents().last().text() || $$("span#source_baidu").contents().last().text() || $$("span#editor_baidu").contents().last().text();
item.content = {
html: description,
text: $$("div#paragraph").text()
};
item.image = image$1;
item.banner = image$1;
item.language = language;
return item;
})));
const image = new URL($("meta[property=\"og:image\"]").prop("content"), rootUrl).href;
return {
title: `${author} - ${$("title").text()}`,
description: $("meta[name=\"description\"]").prop("content"),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author,
language
};
};
const route = {
path: "/zt/:id?",
name: "专题",
url: "ithome.com",
maintainers: ["nczitzk"],
handler,
example: "/ithome/zt/xijiayi",
parameters: { category: "专题 id,默认为 xijiayi,即 [喜加一](https://www.ithome.com/zt/xijiayi),可在对应专题页 URL 中找到" },
description: `::: tip
更多专题请见 [IT之家专题](https://www.ithome.com/zt)
:::`,
categories: ["new-media"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["ithome.com/zt/:id"],
target: "/zt/:id"
}]
};
//#endregion
export { handler, route };