/
posts.ts
65 lines (56 loc) 路 1.69 KB
/
posts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/posts/:topic/:id',
categories: ['game'],
example: '/itch/posts/9539/introduce-yourself',
parameters: { topic: 'Topic id, can be found in URL', id: 'Topic name, can be found in URL' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['itch.io/t/:topic/:id'],
},
],
name: 'Posts',
maintainers: ['nczitzk'],
handler,
};
async function handler(ctx) {
const topic = ctx.req.param('topic');
const id = ctx.req.param('id');
const rootUrl = 'https://itch.io';
const currentUrl = `${rootUrl}/t/${topic}/${id}?before=999999999`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
const items = $('.post_grid')
.toArray()
.map((item) => {
item = $(item);
const author = item.find('.post_author').text();
const description = item.find('.post_body');
return {
author,
description: description.html(),
title: `${author}: ${description.text()}`,
link: item.find('.post_date a').attr('href'),
pubDate: parseDate(item.find('.post_date').attr('title')),
};
});
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}