rsshub
Version:
Make RSS Great Again!
67 lines (65 loc) • 2.07 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 "./ofetch-DKl_Ma9g.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.mjs";
import "./helpers-Bo4JQYdN.mjs";
import { t as got_default } from "./got-CO-ndVl2.mjs";
import { load } from "cheerio";
//#region lib/routes/v2ex/tab.ts
const route = {
path: "/tab/:tabid",
categories: ["bbs"],
view: ViewType.Articles,
example: "/v2ex/tab/hot",
parameters: { tabid: "tab标签ID,在 URL 可以找到" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "标签",
maintainers: ["liyefox"],
handler
};
async function handler(ctx) {
const tabid = ctx.req.param("tabid");
const host = "https://v2ex.com";
const pageUrl = `${host}/?tab=${tabid}`;
const $ = load((await got_default({
method: "get",
url: pageUrl
})).data);
const links = $("span.item_title > a").toArray().slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 10).map((link) => `${host}${$(link).attr("href").replace(/#.*$/, "")}`);
const items = await Promise.all(links.map((link) => cache_default.tryGet(`v2ex-${link}`, async () => {
const $ = load((await got_default({
method: "get",
url: link
})).data);
const replyContent = $("[id^=\"r_\"]").toArray().map((item) => {
const post = $(item);
const content = post.find(".reply_content").html();
const author = post.find(".dark").first().text();
return `<p><div>#${post.find(".no").text()}: <i>${author}</i></div><div>${content}</div></p>`;
}).join("");
return {
title: $(".header h1").text(),
link,
description: `${$("div.topic_content").html()}<div>${replyContent}</div>`,
author: $("div.header > small > a").text()
};
})));
return {
title: `V2EX-${tabid}`,
link: pageUrl,
description: `V2EX-tab-${tabid}`,
item: items
};
}
//#endregion
export { route };