Files
RSSHub/lib/routes/itch/index.ts
T
DIYgod cf4e772de8 refactor: replace art template with jsx (#20777)
* refactor: replace art template with jsx

* fix: tsx files

* fix: renderToString import

* fix: hono html raw import

* feat: remove art
2025-12-29 12:27:32 +08:00

68 lines
1.7 KiB
TypeScript

import { load } from 'cheerio';
import type { Route } from '@/types';
import cache from '@/utils/cache';
import { getSubPath } from '@/utils/common-utils';
import got from '@/utils/got';
import { renderDescription } from './templates/description';
export const route: Route = {
path: '*',
name: 'Unknown',
maintainers: [],
handler,
};
async function handler(ctx) {
const rootUrl = 'https://itch.io';
const currentUrl = `${rootUrl}${getSubPath(ctx)}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
let items = $('.title.game_link')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.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(),
});
return item;
})
)
);
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}