rsshub
Version:
Make RSS Great Again!
79 lines (77 loc) • 2.65 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 { t as utils_default } from "./utils-8S_qiHQV.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/x-mol/news.ts
init_esm_shims();
const route = {
path: "/news/:tag?",
categories: ["study"],
example: "/x-mol/news/3",
parameters: { tag: "Tag number, can be obtained from news list URL. Empty value means news index." },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["x-mol.com/news/index"],
target: "/news"
}],
name: "News",
maintainers: ["cssxsh"],
handler,
url: "x-mol.com/news/index"
};
async function handler(ctx) {
const tag = ctx.req.param("tag");
const urlPath = tag ? `news/tag/${tag}` : "news/index";
const link = new URL(urlPath, utils_default.host).href;
const response = await got_default(link);
const data = response.data;
const $ = load(data);
const newsitem = $(".newsitem").toArray().map((element) => {
element = $(element);
const a = element.find("h3 a");
const span = element.find(".space-right-m30");
const author = span.text().replace("来源:", "").trim();
return {
title: a.text(),
link: new URL(a.attr("href"), utils_default.host).href,
description: art(path.join(__dirname, "templates/description-3014b6bf.art"), {
image: element.find("img").attr("src").split("?")[0],
text: element.find(".thsis-div a").text().trim()
}),
author,
pubDate: span.next().length ? timezone(parseDate(span.next().text().trim()), 8) : void 0
};
});
const item = await Promise.all(newsitem.map((item$1) => cache_default.tryGet(item$1.link, async () => {
if (item$1.link.includes("outLinkByIdAndCode")) return item$1;
const description = load((await got_default(item$1.link)).data)(".newscontent");
description.find(".detitemtit, .detposttiau").remove();
item$1.description = description.html();
return item$1;
})));
return {
title: $("title").text(),
link: response.url,
description: $("meta[name=\"description\"]").attr("content"),
item
};
}
//#endregion
export { route };