rsshub
Version:
Make RSS Great Again!
40 lines (39 loc) • 1.51 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { load } from "cheerio";
//#region lib/routes/30secondsofcode/utils.ts
const rootUrl = "https://www.30secondsofcode.org";
async function processList(listElements) {
return (await Promise.allSettled(listElements.map((item) => {
const $ = load(item);
return processItem({
link: $(" article > h3 > a").attr("href"),
date: $(" article > small > time").attr("datetime")
});
}))).map((item) => item.status === "fulfilled" ? item.value : { title: "Error Reading Item" });
}
async function processItem({ link: articleLink, date }) {
return await cache_default.tryGet(`30secondsofcode:${articleLink}`, async () => {
const finalLink = `${rootUrl}${articleLink}`;
const $ = load(await rofetch(finalLink));
const tags = $.root().find("body > main > nav > ol > li:not(:first-child):not(:last-child)").toArray().map((tag) => $(tag).find("a").text());
const article = $("main > article");
const title = article.find("h1").text();
const image = article.find("img").attr("src");
article.find("h1").remove();
const description = article.html();
return {
title,
link: finalLink,
pubDate: parseDate(date),
description,
author: "30 Seconds of Code",
category: tags,
image: `${rootUrl}${image}`,
banner: `${rootUrl}${image}`
};
});
}
//#endregion
export { rootUrl as n, processList as t };