UNPKG

rsshub

Version:
85 lines (81 loc) 3.38 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 "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs"; import { t as isValidHost } from "./valid-host-C-u5eW3j.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/itch/devlog.ts init_esm_shims(); const route = { path: "/devlog/:user/:id", categories: ["game"], example: "/itch/devlog/teamterrible/the-baby-in-yellow", parameters: { user: "User id, can be found in URL", id: "Item id, can be found in URL" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Developer Logs", maintainers: ["nczitzk"], handler, description: `\`User id\` is the field before \`.itch.io\` in the URL of the corresponding page, e.g. the URL of [The Baby In Yellow Devlog](https://teamterrible.itch.io/the-baby-in-yellow/devlog) is \`https://teamterrible.itch.io/the-baby-in-yellow/devlog\`, where the field before \`.itch.io\` is \`teamterrible\`. \`Item id\` is the field between \`itch.io\` and \`/devlog\` in the URL of the corresponding page, e.g. the URL for [The Baby In Yellow Devlog](https://teamterrible.itch.io/the-baby-in-yellow/devlog) is \`https://teamterrible.itch.io/the-baby-in-yellow/devlog\`, where the field between \`itch.io\` and \`/devlog\` is \`the-baby-in-yellow\`. So the route is [\`/itch/devlogs/teamterrible/the-baby-in-yellow\`](https://rsshub.app/itch/devlogs/teamterrible/the-baby-in-yellow).` }; async function handler(ctx) { const user = ctx.req.param("user") ?? ""; const id = ctx.req.param("id") ?? ""; const limit = Number.parseInt(ctx.req.query("limit")) || 20; if (!isValidHost(user)) throw new invalid_parameter_default("Invalid user"); const rootUrl = `https://${user}.itch.io/${id}/devlog`; const $ = load((await got_default({ method: "get", url: rootUrl })).data); let items = $(".title").toArray().slice(0, limit).map((item) => { item = $(item); return { title: item.text(), link: item.attr("href"), pubDate: timezone(parseDate(item.text()), 8) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); const infoJson = content("script[type=\"application/ld+json\"]:contains(\"@type\":\"BlogPosting\")"); const info = JSON.parse(content(infoJson).text()); item.author = info.author.name; item.pubDate = info.datePublished; item.description = art(path.join(__dirname, "templates/description-6541c218.art"), { images: content(".post_image").toArray().map((e) => content(e).attr("src")), description: content(".post_body").html() }); return item; }))); return { title: $("title").text(), link: rootUrl, item: items }; } //#endregion export { route };