rsshub
Version:
Make RSS Great Again!
70 lines (69 loc) • 2.69 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
import { raw } from "hono/html";
//#region lib/routes/nautil/topics.tsx
const baseUrl = "https://nautil.us";
const apiUrl = "https://lede-admin.nautil.us";
const route = {
path: "/topic/:tid",
categories: ["new-media"],
example: "/nautil/topic/arts",
parameters: { tid: "topic" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["nautil.us/topics/:tid"] }],
name: "Topics",
maintainers: ["emdoe"],
handler,
description: "This route provides a flexible plan with full text content to subscribe specific topic(s) on the Nautilus. Please visit [nautil.us](https://nautil.us) and click `Topics` to acquire whole topic list."
};
async function handler(ctx) {
const categoryIdMap = await cache_default.tryGet("nautil:categories", async () => {
const { data } = await got_default(`${apiUrl}/wp-json/wp/v2/categories`, { searchParams: { per_page: 100 } });
return data.map((item) => ({
id: item.id,
name: item.name,
slug: item.slug
}));
});
const { data: list } = await got_default(`${apiUrl}/wp-json/wp/v2/posts`, { searchParams: {
categories: categoryIdMap.find((item) => item.slug === ctx.req.param("tid").toLowerCase()).id,
per_page: ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20
} });
const out = list.map((item) => {
const head = item.yoast_head_json;
const $ = load(item.content.rendered, null, false);
$(".primis-ad, .article-ad, .editorskit-no-mobile").remove();
$("img").each((_, e) => {
const $e = $(e);
$e.attr("src", $e.attr("data-src") ?? $e.attr("srcset"));
$e.attr("src", $e.attr("src").split("?", 1)[0]);
$e.removeAttr("data-src");
$e.removeAttr("srcset");
});
return {
title: item.title.rendered,
author: item.yoast_head_json.author,
description: renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [head.og_image?.length ? head.og_image.map((image) => /* @__PURE__ */ jsx("img", { src: image.url.split("?", 1)[0] })) : null, raw($.html())] })),
link: item.link,
pubDate: parseDate(item.date_gmt)
};
});
return {
title: "Nautilus | " + categoryIdMap.find((item) => item.slug === ctx.req.param("tid").toLowerCase()).name,
link: `${baseUrl}/topics/${ctx.req.param("tid")}/`,
item: out
};
}
//#endregion
export { route };