rsshub
Version:
Make RSS Great Again!
44 lines (43 loc) • 1.48 kB
JavaScript
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs";
import { t as parseDate } from "./parse-date-3kcy2Eau.mjs";
import { t as cache_default } from "./cache-C1Y-9qDV.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 response = await rofetch(rootUrl);
const $ = load(response);
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 () => {
const detailResponse = await rofetch(item.link);
item.description = load(detailResponse)("#cmsMainContent").html() ?? void 0;
return item;
})));
return {
title: `CGTN - Most ${type}`,
link: rootUrl,
item: items
};
}
//#endregion
export { route };