rsshub
Version:
Make RSS Great Again!
70 lines (68 loc) • 2.26 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as rootUrl } from "./utils-CToFK8bM.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/gitpod/blog.ts
init_esm_shims();
const route = {
path: "/blog",
categories: ["programming"],
example: "/gitpod/blog",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["gitpod.io/blog", "gitpod.io/"] }],
name: "Blog",
maintainers: ["TonyRL"],
handler,
url: "gitpod.io/blog"
};
async function handler(ctx) {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 10;
const $ = load((await got_default(rootUrl + "/blog")).data);
let items = $("div[class^=\"flex justify-center\"]").slice(0, limit).toArray().map((item) => {
item = $(item);
return {
title: item.find("h2").text(),
link: rootUrl + item.find("a").attr("href"),
pubDate: parseDate(item.find("span[class^=date]").text())
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default(item.link)).data);
const headerImg = content("img[class^=max-h]");
item.description = art(path.join(__dirname, "templates/description-ab8ee56e.art"), {
img: headerImg.attr("src"),
alt: headerImg.attr("alt"),
content: content("div[class^=content-blog]").html()
});
item.author = content("span.avatars a").toArray().map((e) => content(e).text().trim()).join(", ");
return item;
})));
const ret = {
title: $("title").text(),
link: rootUrl + "/blog",
description: $("meta[name=\"description\"]").attr("content"),
language: "en-US",
item: items
};
ctx.set("json", ret);
return ret;
}
//#endregion
export { route };