rsshub
Version:
Make RSS Great Again!
44 lines (43 loc) • 1.25 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/worldhappiness/news.ts
const route = {
path: "/news",
categories: ["new-media"],
example: "/worldhappiness/news",
name: "News",
maintainers: ["nczitzk"],
handler
};
async function handler() {
const rootUrl = "https://www.worldhappiness.report";
const currentUrl = `${rootUrl}/news/`;
const response = await rofetch(currentUrl);
const $ = load(response);
const list = $(".news-card").toArray().map((item) => {
const $item = $(item);
const a = $item.find("a.post-link");
return {
title: a.text(),
link: new URL(a.attr("href"), rootUrl).href,
pubDate: parseDate($item.find("time.post-date").attr("datetime"))
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await rofetch(item.link);
const content = load(detailResponse);
return {
...item,
description: content(".post-body").html()
};
})));
return {
title: $("head title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };