rsshub
Version:
Make RSS Great Again!
94 lines (92 loc) • 3.47 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.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/bestofjs/monthly.ts
init_esm_shims();
const BASEURL = "https://bestofjs.org/rankings/monthly";
const route = {
path: "/rankings/monthly",
categories: ["programming"],
example: "/bestofjs/rankings/monthly",
view: ViewType.Notifications,
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["bestofjs.org/rankings/monthly/:year/:month"],
target: "/rankings/monthly"
}],
name: "Monthly Rankings",
maintainers: ["ztkuaikuai"],
url: "bestofjs.org/rankings/monthly",
handler: async () => {
const targetMonths = getLastSixMonths();
return {
title: "Best of JS Monthly Rankings",
link: BASEURL,
description: "Monthly rankings of the most popular JavaScript projects on Best of JS",
item: (await Promise.all(targetMonths.map((data) => {
const [year, month] = data.split("-");
return getMonthlyRankings(year, month);
}))).flatMap((oneMonthlyRankings, i) => {
const [year, month] = targetMonths[i].split("-");
const description = art(path.join(__dirname, "templates/description-efeec4a1.art"), { items: oneMonthlyRankings });
return {
title: `Best of JS Monthly Rankings - ${year}/${month}`,
description,
link: `${BASEURL}/${year}/${month}`,
guid: `${BASEURL}/${year}/${month}`,
author: "Best of JS"
};
}),
language: "en"
};
}
};
const getLastSixMonths = () => {
const now = /* @__PURE__ */ new Date();
const currentYear = now.getFullYear();
const currentMonth = now.getMonth() + 1;
return Array.from({ length: 6 }, (_, i) => {
let month = currentMonth - (i + 1);
let year = currentYear;
if (month <= 0) {
month += 12;
year -= 1;
}
return `${year}-${month}`;
});
};
const getMonthlyRankings = (year, month) => {
const targetUrl = `${BASEURL}/${year}/${month}`;
return cache_default.tryGet(targetUrl, async () => {
const $ = load(await ofetch_default(targetUrl));
return $("table.w-full tbody tr[data-testid=\"project-card\"]").toArray().map((el) => {
const $tr = $(el);
return {
logo: $tr.find("td:first img").attr("src")?.replace(/.dark./, ".") || "",
projectName: $tr.find("td:nth-child(2) a[href^=\"/projects/\"]").first().text().trim(),
githubLink: $tr.find("td:nth-child(2) a[href*=\"github.com\"]").attr("href") || "",
homepageLink: $tr.find("td:nth-child(2) a[href*=\"http\"]:not([href*=\"github.com\"])").attr("href") || "",
description: $tr.find("td:nth-child(2) .font-serif").text().trim(),
tags: $tr.find("td:nth-child(2) [href*=\"/projects?tags=\"]").toArray().map((tag) => $(tag).text().trim()),
starCount: $tr.find("td:nth-child(4) span:last").text().trim() || $tr.find("td:nth-child(2) .inline-flex span:last-child").text().trim(),
additionalInfo: $tr.find("td:nth-child(3) > div").toArray().slice(1).map((el$1) => $(el$1).text().trim()).join("; ")
};
});
});
};
//#endregion
export { route };