rsshub
Version:
Make RSS Great Again!
60 lines (58 loc) • 2.04 kB
JavaScript
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as md5 } from "./md5-C8GRvctM.mjs";
import { load } from "cheerio";
//#region lib/routes/techpowerup/utils.ts
const baseUrl = "https://www.techpowerup.com";
const headers = { cookie: `botcheck=${md5(Date.now().toString())}` };
const fixImages = ($) => {
$("div.responsive-image-xx").each((_, d) => {
removeResponsiveStyle(d);
});
$("figure").each((_, f) => {
removeFigureStyle(f);
});
$(".newspost img").each((_, img) => {
hdImage(img);
});
};
const hdImage = (img) => {
img.attribs.src = img.attribs.src.replace("_thm", "").replace("_small", "");
if (img.parentNode.name === "a" && img.parentNode.attribs["data-width"] && img.parentNode.attribs["data-height"]) {
img.attribs.width = img.parentNode.attribs["data-width"];
img.attribs.height = img.parentNode.attribs["data-height"];
}
};
const removeFigureStyle = (f) => {
delete f.attribs.style;
};
const removeResponsiveStyle = (div) => {
delete div.attribs.style;
};
const parseReviews = async ($, item) => {
const { review } = JSON.parse($("script[type=\"application/ld+json\"]").text());
const content = $(".text");
const nextPages = $("#pagesel option").toArray().map((a) => `${baseUrl}${a.attribs.value}`).slice(1, -1);
if (nextPages.length) {
const pages = await Promise.all(nextPages.map(async (url) => {
const $$1 = load(await ofetch_default(url, { headers }));
$$1(".text div.responsive-image-xx").each((_, d) => {
removeResponsiveStyle(d);
});
$$1(".text figure").each((_, f) => {
removeFigureStyle(f);
});
$$1(".text img").each((_, img) => {
hdImage(img);
});
return $$1(".text").html();
}));
content.append(pages);
}
item.author = review.author.name;
item.pubDate = parseDate(review.datePublished);
item.updated = parseDate(review.dateModified);
item.description = content.html();
};
//#endregion
export { parseReviews as i, fixImages as n, headers as r, baseUrl as t };