UNPKG

rsshub

Version:
85 lines (82 loc) 2.44 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { load } from "cheerio"; //#region lib/routes/hbr/topic.ts const route = { path: "/topic/:topic?/:type?", categories: ["new-media"], example: "/hbr/topic/Leadership/Popular", parameters: { topic: "Topic, can be found in URL, Leadership by default", type: { description: "Type, see below, Popular by default", options: [ { value: "Popular", label: "Popular" }, { value: "From the Store", label: "From the Store" }, { value: "For You", label: "For You" } ], default: "Popular" } }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["hbr.org/topic/:topic?", "hbr.org/"] }], name: "Topic", maintainers: ["nczitzk", "pseudoyu"], handler, description: `| POPULAR | FROM THE STORE | FOR YOU | | ------- | -------------- | ------- | | Popular | From the Store | For You | ::: tip Click here to view [All Topics](https://hbr.org/topics) :::` }; async function handler(ctx) { const topic = ctx.req.param("topic") ?? "Leadership"; const type = ctx.req.param("type") ?? "Popular"; const rootUrl = "https://hbr.org"; const currentUrl = `${rootUrl}/topic/${topic}`; const $ = load(await ofetch_default(currentUrl)); const list = $(`stream-content[data-stream-name="${type}"]`).find(".stream-item").toArray().map((item) => { item = $(item); return { title: item.attr("data-title"), author: item.attr("data-authors"), category: item.attr("data-topic"), link: `${rootUrl}${item.attr("data-url")}` }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load(await ofetch_default(item.link)); item.description = content(".article-body, article[itemprop=\"description\"]").html(); item.pubDate = parseDate(content("meta[property=\"article:published_time\"]").attr("content")); return item; }))); return { title: `${$("title").eq(0).text()} - ${type}`, link: currentUrl, item: items }; } //#endregion export { route };