UNPKG

rsshub

Version:
64 lines (62 loc) 2.49 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { t as rss_parser_default } from "./rss-parser-Cnh4NKwh.mjs"; import { Fragment, jsxs } from "hono/jsx/jsx-runtime"; import { load } from "cheerio"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/gameapps/index.tsx 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 $ = load(await ofetch_default(url, { headers: { referer: item.link } })); $(".pages").remove(); return $(".news-content").html(); })); content.append(pages); } const intro = $("div.introduction.media.news-intro div.media-body").html()?.trim(); const desc = content.html()?.trim(); item.description = renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [intro ? raw(intro) : null, desc ? raw(desc) : null] })); 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 };