rsshub
Version:
Make RSS Great Again!
37 lines (36 loc) • 1.4 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/gameres/utils.ts
const rootUrl = "https://www.gameres.com";
const getFeed = async (currentUrl, query) => {
const $ = load(await rofetch(currentUrl));
const list = $(query).slice(0, 20).toArray().map((item) => {
const $item = $(item);
const a = $item.parent().get(0).tagName === "a" ? $item.parent() : $item.children();
return {
title: a.text(),
description: $item.parent().find("p").text(),
link: `${rootUrl}${a.attr("href")}`
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
if (item.link.includes("/wl?")) return item;
const content = load(await rofetch(item.link));
const payload = JSON.parse(content("#__NUXT_DATA__").text());
const article = payload.find((entry) => entry instanceof Object && "dateline" in entry && "content_html" in entry);
item.description = payload[article.content_html];
item.title = payload[article.subject];
item.pubDate = parseDate(payload[article.dateline] * 1e3);
item.author = payload[article.author];
return item;
})));
return {
title: $("title").text(),
link: rootUrl,
item: items
};
};
//#endregion
export { rootUrl as n, getFeed as t };