UNPKG

rsshub

Version:
86 lines (84 loc) 2.7 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs"; import { t as getHeaders } from "./utils-BXkxCuHO.mjs"; import { load } from "cheerio"; //#region lib/routes/smzdm/haowen.ts const route = { path: "/haowen/:day?", categories: ["shopping"], example: "/smzdm/haowen/1", parameters: { day: { description: "以天为时间跨度,默认为 `1`", options: [ { value: "1", label: "今日热门" }, { value: "7", label: "周热门" }, { value: "30", label: "月热门" } ], default: "1" } }, features: { requireConfig: [{ name: "SMZDM_COOKIE", description: "什么值得买登录后的 Cookie 值" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "好文", maintainers: ["LogicJake", "pseudoyu"], handler }; async function handler(ctx) { if (!config.smzdm.cookie) throw new config_not_found_default("什么值得买排行榜 is disabled due to the lack of SMZDM_COOKIE"); const link = `https://post.smzdm.com/hot_${ctx.req.param("day") ?? "1"}/`; const $ = load(await ofetch_default(link, { headers: getHeaders() })); const title = $("li.filter-tab.active").text(); const list = $("li.feed-row-wide").toArray().map((item) => { const $item = $(item); return { title: $item.find("h5.z-feed-title a").text(), link: $item.find("h5.z-feed-title a").attr("href"), pubDate: timezone(parseDate($item.find("span.z-publish-time").text()), 8) }; }); const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link ?? "", async () => { const $$1 = load(await ofetch_default(item.link ?? "", { headers: getHeaders() })); const content = $$1("#articleId"); content.find(".item-name").remove(); content.find(".recommend-tab").remove(); const releaseDate = $$1("meta[property=\"og:release_date\"]").attr("content"); return { title: item.title, link: item.link, description: content.html() || "", pubDate: releaseDate ? timezone(parseDate(releaseDate), 8) : item.pubDate, author: $$1("meta[property=\"og:author\"]").attr("content") || "" }; }))); return { title: `${title}-什么值得买好文`, link, item: out.filter((item) => item !== null) }; } //#endregion export { route };