UNPKG

rsshub

Version:
39 lines (38 loc) 1.47 kB
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/gameres/utils.ts const rootUrl = "https://www.gameres.com"; const getFeed = async (currentUrl, query) => { const response = await rofetch(currentUrl); const $ = load(response); 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 detailResponse = await rofetch(item.link); const content = load(detailResponse); 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 };