rsshub
Version:
Make RSS Great Again!
71 lines (69 loc) • 2.66 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/producthunt/today.ts
init_esm_shims();
const route = {
path: "/today",
categories: ["other"],
example: "/producthunt/today",
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["www.producthunt.com/"] }],
name: "Top Products Launching Today",
maintainers: ["miaoyafeng", "Fatpandac"],
handler,
url: "www.producthunt.com/"
};
async function handler() {
const match = load(await ofetch_default("https://www.producthunt.com/", { headers: { "User-Agent": config.trueUA } }))("script:contains(\"ApolloSSRDataTransport\")").text().match(/"events":(\[.+\])\}\)/)?.[1]?.trim().replaceAll("undefined", "null");
const list = JSON.parse(match).find((event) => event.type === "next" && event.value.data.homefeed).value.data.homefeed.edges.find((edge) => edge.node.id === "FEATURED-0").node.items.filter((i) => i.__typename === "Post").map((item) => ({
title: item.name,
link: `https://www.producthunt.com/products/${item.product.slug}`,
postSlug: item.slug,
description: item.tagline,
pubDate: parseDate(item.createdAt),
image: `https://ph-files.imgix.net/${item.thumbnailImageUuid}`,
categories: item.topics.edges.map((topic) => topic.node.name)
}));
return {
title: "Product Hunt Today Popular",
link: "https://www.producthunt.com/",
item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const post = (await ofetch_default("https://www.producthunt.com/frontend/graphql", {
method: "POST",
headers: { "User-Agent": config.trueUA },
body: {
operationName: "PostPage",
variables: { slug: item.postSlug },
extensions: { persistedQuery: {
version: 1,
sha256Hash: "488585149898ee974a51884b11e205c34ea8ad34ee01d47d7936a66a6db799ff"
} }
}
})).data.post;
item.author = post.user.name;
item.description = art(path.join(__dirname, "templates/description-994faa20.art"), {
tagline: post.tagline,
description: post.description,
media: post.media
});
return item;
})))
};
}
//#endregion
export { route };