rsshub
Version:
Make RSS Great Again!
50 lines (49 loc) • 1.75 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as config } from "./config-Bpyy15zS.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as ConfigNotFoundError } from "./config-not-found-fQ5mxvDU.mjs";
import { load } from "cheerio";
//#region lib/routes/hexo/fluid.ts
const route = {
path: "/fluid/:url",
categories: ["blog"],
example: "/hexo/fluid/hexo.fluid-dev.com",
parameters: { url: "the blog URL without the protocol (http:// and https://)" },
name: "Blog using Fluid theme",
maintainers: ["gao-keyong"],
features: { requireConfig: [{
name: "ALLOW_USER_SUPPLY_UNSAFE_DOMAIN",
description: "Allow user supplied domain"
}] },
handler
};
async function handler(ctx) {
if (!config.feature.allow_user_supply_unsafe_domain) throw new ConfigNotFoundError(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`);
const url = `http://${ctx.req.param("url")}`;
const $ = load(await rofetch(`${url}/archives/`));
const list = $(".list-group-item").slice(0, 5).toArray().map((element) => {
const each = $(element);
const storyLink = each.attr("href");
return {
title: each.find(".archive-post-title").text(),
link: new URL(storyLink, url).href
};
});
const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const $ = load(await rofetch(item.link));
return {
...item,
pubDate: parseDate($("time").attr("datetime")),
description: $(".markdown-body").html()
};
})));
return {
title: $(".navbar-brand strong").text(),
link: url,
description: $("[name=description]").attr("content"),
item: out
};
}
//#endregion
export { route };