rsshub
Version:
Make RSS Great Again!
55 lines (52 loc) • 1.89 kB
JavaScript
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { t as renderDescription } from "./description-BP-TG2x9.mjs";
import { load } from "cheerio";
//#region lib/routes/itch/index.ts
const route = {
path: "/:path{.+}?",
categories: ["game"],
example: "/itch/games/new-and-popular/featured",
parameters: { path: "Params" },
name: "Browse",
maintainers: ["nczitzk"],
description: `The path is the field after \`itch.io\` in the URL of the corresponding page, e.g. the URL of [Top Rated Games tagged Singleplayer](https://itch.io/games/top-rated/tag-singleplayer) is \`https://itch.io/games/top-rated/tag-singleplayer\`, where the field after \`itch.io\` is \`/games/top-rated/tag-singleplayer\`.
So the route is [\`/itch/games/top-rated/tag-singleplayer\`](https://rsshub.app/itch/games/top-rated/tag-singleplayer).
::: tip
You can browse all the tags [here](https://itch.io/tags).
:::`,
handler
};
async function handler(ctx) {
const currentUrl = `https://itch.io/${ctx.req.param("path") ?? ""}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
let items = $(".title.game_link").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 content = load((await got_default({
method: "get",
url: item.link
})).data);
item.author = content("title").text().split("by ").pop();
item.description = renderDescription({
images: content(".screenshot").toArray().map((i) => content(i).attr("src")),
description: content(".formatted_description").html() ?? void 0
});
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };