rsshub
Version:
Make RSS Great Again!
42 lines (41 loc) • 1.18 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/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 $ = load(await rofetch(currentUrl));
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 content = load(await rofetch(item.link));
return {
...item,
description: content(".post-body").html()
};
})));
return {
title: $("head title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };