UNPKG

rsshub

Version:
90 lines (84 loc) 3.13 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { load } from "cheerio"; //#region lib/routes/gamersecret/index.ts const route = { path: "/:type?/:category?", categories: ["game"], example: "/gamersecret", parameters: { type: "Type, see below, Latest News by default", category: "Category, see below" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: [ "gamersecret.com/:type", "gamersecret.com/:type/:category", "gamersecret.com/" ] }], name: "Category", maintainers: ["nczitzk"], handler, description: `| Latest News | PC | Playstation | Nintendo | Xbox | Moblie | | ----------- | -- | ----------- | -------- | ---- | ------ | | latest-news | pc | playstation | nintendo | xbox | moblie | Or | GENERAL | GENERAL EN | MOBILE | MOBILE EN | | ---------------- | ------------------ | --------------- | ----------------- | | category/general | category/generalen | category/mobile | category/mobileen | | NINTENDO | NINTENDO EN | PC | PC EN | | ----------------- | ------------------- | ----------- | ------------- | | category/nintendo | category/nintendoen | category/pc | category/pcen | | PLAYSTATION | PLAYSTATION EN | REVIEWS | | -------------------- | ---------------------- | ---------------- | | category/playstation | category/playstationen | category/reviews | | XBOX | XBOX EN | | ------------- | --------------- | | category/xbox | category/xboxen |` }; async function handler(ctx) { const type = ctx.req.param("type") ?? "latest-news"; const category = ctx.req.param("category") ?? ""; const currentUrl = `https://www.gamersecret.com/${type}${category ? `/${category}` : ""}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $(".jeg_post_title a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20).toArray().map((item) => { const $item = $(item); return { title: $item.text(), link: $item.attr("href") }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await got_default({ method: "get", url: item.link }); const content = load(detailResponse.data); content("img").each((_, el) => { content(el).attr("src", content(el).attr("data-src")); }); item.author = content(".jeg_meta_author").text().replace(/by/, ""); item.pubDate = timezone(parseDate(detailResponse.data.match(/datePublished":"(.*)","dateModified/)[1]), 8); item.description = content(".thumbnail-container").html() + content(".elementor-text-editor, .content-inner").html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };