UNPKG

rsshub

Version:
65 lines (63 loc) 2.44 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as rss_parser_default } from "./rss-parser-Dtop7M8f.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/gameapps/index.ts init_esm_shims(); const route = { path: "/", example: "/gameapps", radar: [{ source: ["gameapps.hk/"] }], name: "最新消息", maintainers: ["TonyRL"], handler, url: "gameapps.hk/" }; async function handler() { const baseUrl = "https://www.gameapps.hk"; const feed = await rss_parser_default.parseURL(`${baseUrl}/rss`); const items = await Promise.all(feed.items.map((item) => cache_default.tryGet(item.link, async () => { const $ = load(await ofetch_default(item.link, { headers: { Referer: baseUrl } })); item.title = $("meta[property=\"og:title\"]").attr("content") ?? $(".news-title h1").text(); const nextPages = $(".pagination li").not(".disabled").not(".active").find("a").toArray().map((a) => `${baseUrl}${a.attribs.href}`); $(".pages").remove(); const content = $(".news-content"); delete item.content; delete item.contentSnippet; delete item.isoDate; if (nextPages.length) { const pages = await Promise.all(nextPages.map(async (url) => { const $$1 = load(await ofetch_default(url, { headers: { referer: item.link } })); $$1(".pages").remove(); return $$1(".news-content").html(); })); content.append(pages); } item.description = art(path.join(__dirname, "templates/description-0048aaa9.art"), { intro: $("div.introduction.media.news-intro div.media-body").html()?.trim(), desc: content.html()?.trim() }); item.guid = item.guid.slice(0, item.link.lastIndexOf("/")); item.pubDate = parseDate(item.pubDate); item.enclosure_url = $("div.introduction.media.news-intro div.media-left").find("img").attr("src"); item.enclosure_type = "image/jpeg"; return item; }))); return { title: feed.title, link: feed.link, description: feed.description, image: `${baseUrl}/static/favicon/apple-touch-icon.png`, item: items, language: feed.language }; } //#endregion export { route };