rsshub
Version:
Make RSS Great Again!
72 lines (71 loc) • 2.18 kB
JavaScript
import { n as parseRelativeDate, 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/indienova/gamedb.ts
const route = {
name: "GameDB 游戏库",
path: "/gamedb/recent/:platform?",
example: "/indienova/gamedb/recent",
categories: ["game"],
parameters: { platform: {
description: "平台,留空为 `all`",
options: [
{
value: "all",
label: "全部"
},
{
value: "ps4",
label: "PS4"
},
{
value: "xboxone",
label: "XBOX One"
},
{
value: "nintendo-switch",
label: "Nintendo Switch"
}
],
default: "all"
} },
maintainers: ["TonyRL"],
handler
};
async function handler(ctx) {
const { platform = "all" } = ctx.req.param();
const baseUrl = "https://indienova.com";
const { data: response, url: link } = await got_default(`${baseUrl}/gamedb/recent/${platform}/p/1`);
const $ = load(response);
const list = $(".related-game").toArray().map((item) => {
const $item = $(item);
return {
title: $item.find("span").contents().filter((_, el) => el.nodeType === 3).text(),
link: new URL($item.find("a").attr("href"), baseUrl).href,
pubDate: parseRelativeDate($item.find("small").first().text())
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const { data: response } = await got_default(item.link);
const $ = load(response);
const featureBox = $(".feature-box");
if (featureBox.length) {
item.description = featureBox.find("p").first().text();
return item;
}
const article = $(".row article");
article.find("#showHiddenText").remove();
item.description = $(".cover-image").prop("outerHTML") + $(".tab-container").html() + article.html();
item.pubDate = $(".gamedb-release").length ? timezone(parseDate($(".gamedb-release").text().replaceAll(/[()]/g, "")), 8) : item.pubDate;
return item;
})));
return {
title: $("head title").text(),
link,
item: items
};
}
//#endregion
export { route };