rsshub
Version:
Make RSS Great Again!
52 lines (51 loc) • 1.51 kB
JavaScript
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as got_default } from "./got-BDnf4rdT.mjs";
import { load } from "cheerio";
//#region lib/routes/thegradient/index.ts
const route = {
path: "/posts",
categories: ["blog"],
example: "/thegradient/posts",
radar: [{ source: ["thegradient.pub/"] }],
url: "thegradient.pub/",
name: "Posts",
maintainers: ["liyaozhong"],
handler,
description: "The Gradient Blog Posts"
};
async function handler() {
const rootUrl = "https://thegradient.pub";
const $ = load((await got_default(rootUrl)).data);
const posts = $(".c-post-card-wrap").toArray().map((item) => {
const $item = $(item);
const $link = $item.find(".c-post-card__title-link");
const $meta = $item.find(".c-post-card__meta");
const href = $link.attr("href");
const title = $link.text().trim();
const dateStr = $meta.find("time").attr("datetime");
if (!href || !title || !dateStr) return null;
return {
title,
link: new URL(href, rootUrl).href,
pubDate: parseDate(dateStr)
};
}).filter((post) => post !== null);
return {
title: "The Gradient Blog",
link: rootUrl,
item: await Promise.all(posts.map((post) => cache_default.tryGet(post.link, async () => {
try {
const $detail = load((await got_default(post.link)).data);
return {
...post,
description: $detail(".c-content").html()
};
} catch {
return post;
}
})))
};
}
//#endregion
export { route };