rsshub
Version:
Make RSS Great Again!
42 lines (41 loc) • 1.41 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/cgtn/most.ts
const route = {
path: "/most/:type?/:time?",
categories: ["new-media"],
example: "/cgtn/most/read/day",
parameters: {
type: "Type, `read` as most read, `share` as most share, `read` by default",
time: "Time range, `all` as all the time, `day` as today, `week` as this week, `month` as this month, `year` as this year, `all` by default"
},
name: "Most Read & Most Share",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const { type = "read", time = "all" } = ctx.req.param();
const rootUrl = `https://www.cgtn.com/most-${type}`;
const $ = load(await rofetch(rootUrl));
const list = $(`#${time}Items div.most-read-item-box div.cg-title`).toArray().map((item) => {
const a = $(item).find("a");
return {
title: a.text(),
link: a.attr("href"),
pubDate: parseDate(Number.parseInt(a.attr("data-time")))
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
item.description = load(await rofetch(item.link))("#cmsMainContent").html() ?? void 0;
return item;
})));
return {
title: `CGTN - Most ${type}`,
link: rootUrl,
item: items
};
}
//#endregion
export { route };