/
index.ts
94 lines (82 loc) 路 3 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
import cache from '@/utils/cache';
import got from '@/utils/got';
import parser from '@/utils/rss-parser';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
export const route: Route = {
path: '/',
radar: [
{
source: ['gameapps.hk/'],
target: '',
},
],
name: 'Unknown',
maintainers: ['TonyRL'],
handler,
url: 'gameapps.hk/',
};
async function handler() {
const baseUrl = 'https://www.gameapps.hk';
const feed = await parser.parseURL(`${baseUrl}/rss`);
const items = await Promise.all(
feed.items.map((item) =>
cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link, {
headers: {
Referer: baseUrl,
},
});
const $ = load(response);
const nextPages = $('.pagination li')
.not('.disabled')
.not('.active')
.find('a')
.toArray()
.map((a) => `${baseUrl}${a.attribs.href}`);
$('.pages').remove();
const content = $('.news-content');
// remove unwanted key value
delete item.content;
delete item.contentSnippet;
delete item.isoDate;
if (nextPages.length) {
const pages = await Promise.all(
nextPages.map(async (url) => {
const { data: response } = await got(url, {
headers: {
referer: item.link,
},
});
const $ = load(response);
$('.pages').remove();
return $('.news-content').html();
})
);
content.append(pages);
}
item.description = art(path.join(__dirname, 'templates/description.art'), {
src: $('div.introduction.media.news-intro div.media-left').find('img').attr('src'),
intro: $('div.introduction.media.news-intro div.media-body').html().trim(),
desc: content.html().trim(),
});
item.guid = item.guid.substring(0, item.link.lastIndexOf('/'));
item.pubDate = parseDate(item.pubDate);
return item;
})
)
);
return {
title: feed.title,
link: feed.link,
description: feed.description,
image: `${baseUrl}/static/favicon/apple-touch-icon.png`,
item: items,
language: feed.language,
};
}