rsshub
Version:
Make RSS Great Again!
76 lines (74 loc) • 2.87 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 { n as parseRelativeDate, 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/zhubai/top20.ts
init_esm_shims();
const parseContent = (content) => art(path.join(__dirname, "templates/description-4270576b.art"), { content });
art.defaults.imports.parseContent = parseContent;
const route = {
path: "/top20",
categories: ["blog"],
example: "/zhubai/top20",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["analy.zhubai.love/"] }],
name: "上周热门 TOP 20",
maintainers: ["nczitzk"],
handler,
url: "analy.zhubai.love/"
};
async function handler(ctx) {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20;
const rootUrl = "http://analy.zhubai.wiki";
const apiUrl = new URL("a/zb/s/ht/pl/wk", "https://open.zhubai.wiki").href;
const { data: response } = await got_default.post(apiUrl);
let items = response.data.slice(0, limit).map((item) => ({
title: item.pn,
link: item.pu ?? item.pq ?? item.fp,
description: item.pa,
author: item.zn,
pubDate: parseRelativeDate(item.lu.replace(/\.\d+/, ""))
}));
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const matches = item.link.match(/\/(?:pl|pq|fp)\/([\w-]+)\/(\d+)/);
const { data } = await got_default(`https://${matches[1]}.zhubai.love/api/posts/${matches[2]}`);
item.title = data.title ?? item.title;
item.description = data.content ? parseContent(JSON.parse(data.content)) : item.description;
item.author = data.author?.name ?? item.author;
item.pubDate = data.created_at ? parseDate(data.created_at) : item.pubDate;
return item;
})));
const { data: currentResponse } = await got_default(rootUrl);
const $ = load(currentResponse);
const icon = $("link[rel=\"apple-touch-icon\"]").prop("href");
return {
item: items,
title: `${$("meta[property=\"og:title\"]").prop("content")} - TOP20`,
link: rootUrl,
description: $("meta[property=\"og:description\"]").prop("content"),
language: $("html").prop("lang"),
image: $("meta[property=\"og:image\"]").prop("content"),
icon,
logo: icon,
subtitle: $("meta[property=\"og:description\"]").prop("content"),
author: $("meta[name=\"twitter:site\"]").prop("content")
};
}
//#endregion
export { route };