rsshub
Version:
Make RSS Great Again!
52 lines (50 loc) • 1.91 kB
JavaScript
import "./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 got_default } from "./got-KxxWdaxq.mjs";
import "./timezone-D8cuwzTY.mjs";
import { n as ossUrl, r as rootUrl, t as ProcessFeed } from "./utils-BEAy1lIf.mjs";
import { load } from "cheerio";
//#region lib/routes/aisixiang/toplist.ts
const route = {
path: ["/ranking/:id?/:period?", "/toplist/:id?/:period?"],
name: "Unknown",
maintainers: ["HenryQW", "nczitzk"],
handler,
description: `| 文章点击排行 | 最近更新文章 | 文章推荐排行 |
| ------------ | ------------ | ------------ |
| 1 | 10 | 11 |`
};
async function handler(ctx) {
const { id = "1", period = "1" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 30;
const currentUrl = new URL(`toplist${id ? `?id=${id}${id === "1" ? `&period=${period}` : ""}` : ""}`, rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
const title = `${$("a.hl").text() || ""}${$("title").text().split("_")[0]}`;
const items = $("div.tops_list").slice(0, limit).toArray().map((item) => {
item = $(item);
const a = item.find("div.tips a");
return {
title: a.text(),
link: new URL(a.prop("href"), rootUrl).href,
author: item.find("div.name").text(),
pubDate: parseDate(item.find("div.times").text())
};
});
return {
item: await ProcessFeed(limit, cache_default.tryGet, items),
title: `爱思想 - ${title}`,
link: currentUrl,
language: "zh-cn",
image: new URL("images/logo_toplist.jpg", ossUrl).href,
subtitle: title
};
}
//#endregion
export { route };