rsshub
Version:
Make RSS Great Again!
100 lines (98 loc) • 2.55 kB
JavaScript
import "./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 * as cheerio from "cheerio";
//#region lib/routes/rsshub/routes.ts
const route = {
path: "/routes/:lang?",
categories: ["program-update"],
view: ViewType.Notifications,
example: "/rsshub/routes/en",
parameters: { lang: {
description: "Language",
options: [{
label: "Chinese",
value: "zh"
}, {
label: "English",
value: "en"
}],
default: "en"
} },
radar: [{
source: ["docs.rsshub.app/*"],
target: "/routes"
}],
name: "New routes",
maintainers: ["DIYgod"],
handler,
url: "docs.rsshub.app/*"
};
async function handler(ctx) {
const isEnglish = ctx.req.param("lang") !== "zh";
const lang = isEnglish ? "" : "zh/";
const list = (await Promise.all([
"social-media",
"new-media",
"traditional-media",
"bbs",
"blog",
"programming",
"design",
"live",
"multimedia",
"picture",
"anime",
"program-update",
"university",
"forecast",
"travel",
"shopping",
"game",
"reading",
"government",
"study",
"journal",
"finance",
"other"
].map(async (type) => {
const response = await ofetch_default(`https://docs.rsshub.app/${lang}routes/${type}`);
const $ = cheerio.load(response);
return {
page: $(".page").toArray(),
item: $(".routeBlock").toArray(),
type
};
}))).flatMap(({ page, item, type }) => item.map((item$1) => ({
page,
item: item$1,
type
})));
return {
title: isEnglish ? "RSSHub has new routes" : "RSSHub 有新路由啦",
link: "https://docs.rsshub.app",
description: isEnglish ? "Everything is RSSible" : "万物皆可 RSS",
language: isEnglish ? "en-us" : "zh-cn",
item: list.map(({ page, item, type }) => {
const $ = cheerio.load(page);
const $item = $(item);
const h2Title = $item.prevAll("h2").eq(0);
const h3Title = $item.prevAll("h3").eq(0);
$item.find(".VPBadge").each((_, ele) => {
const $ele = $(ele);
if ($ele.text().includes("Test")) $ele.remove();
});
return {
title: `${h2Title.text().trim()} - ${h3Title.text().trim()}`,
description: $item.html()?.replaceAll(/<!--.*?-->/g, ""),
link: `https://docs.rsshub.app/${lang}routes/${type}#${encodeURIComponent(h2Title.find(".header-anchor").attr("href") && h3Title.find(".header-anchor").attr("href")?.slice(1))}`,
guid: $item.attr("id")
};
})
};
}
//#endregion
export { route };