rsshub
Version:
Make RSS Great Again!
106 lines (104 loc) • 3.35 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 path from "node:path";
import { load } from "cheerio";
//#region lib/routes/luolei/index.ts
init_esm_shims();
const unblurImages = ($) => {
$("img[data-original-src]").each((_, el) => {
el = $(el);
el.replaceWith(art(path.join(__dirname, "templates/description-8179d61b.art"), { images: [{ src: el.prop("data-original-src") }] }));
});
return $;
};
const handler = async (ctx) => {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 50;
const rootUrl = "https://luolei.org";
const { data: response } = await got_default(rootUrl);
const $ = load(response);
const language = $("html").prop("lang");
const themeEl = $("link[rel=\"modulepreload\"]").toArray().findLast((l) => /theme\..*\.js$/.test($(l).prop("href")));
const { data: themeResponse } = await got_default(themeEl ? new URL($(themeEl).prop("href"), rootUrl).href : void 0);
let items = themeResponse.match(/{"title":".*?"string":".*?"}}/g).slice(0, limit).map((item) => {
item = JSON.parse(item.replaceAll(String.raw`\\"`, String.raw`\"`).replaceAll(String.raw`\\n`, "").replaceAll("\\`", "`"));
const $$ = unblurImages(load(item.excerpt));
const title = item.title;
const description = $$.html();
const image$1 = item.cover;
return {
title,
description,
pubDate: parseDate(item.date.time, "x"),
link: new URL(item.url, rootUrl).href,
category: item.categories,
author: item.author,
content: {
html: description,
text: description
},
image: image$1,
banner: image$1,
language
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
if (item.description.length > 40) return item;
const { data: detailResponse } = await got_default(item.link);
const $$ = unblurImages(load(detailResponse));
$$("div.tweet-card").remove();
const title = $$("h2").first().text();
const description = $$("div.vp-doc").html();
item.title = title;
item.description = description;
item.content = {
html: description,
text: $$("div.vp-doc").text()
};
item.language = language;
return item;
})));
const image = new URL($("img.logo").prop("src"), rootUrl).href;
return {
title: $("title").first().text(),
description: $("meta[name=\"description\"]").prop("content"),
link: rootUrl,
item: items,
allowEmpty: true,
image,
author: $("meta[property=\"og:title\"]").prop("content"),
language
};
};
const route = {
path: "/",
name: "罗磊的独立博客",
url: "luolei.org",
maintainers: ["nczitzk"],
handler,
example: "/luolei",
description: "",
categories: ["blog"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["luolei.org"],
target: "/"
}]
};
//#endregion
export { handler, route };