/
news.ts
52 lines (48 loc) 路 1.62 KB
/
news.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
import { Route } from '@/types';
import { parseDate } from '@/utils/parse-date';
import got from '@/utils/got';
import { config } from '@/config';
export const route: Route = {
path: '/news/:lang?',
categories: ['other'],
example: '/atptour/news/en',
parameters: { lang: 'en or es.' },
radar: [
{
source: ['atptour.com'],
},
],
name: 'News',
maintainers: ['LM1207'],
handler,
};
async function handler(ctx) {
const baseUrl = 'https://www.atptour.com';
const favIcon = `${baseUrl}/assets/atptour/assets/favicon.ico`;
const { lang = 'en' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15;
const link = `${baseUrl}/${lang}/-/tour/news/latest-filtered-results/0/${limit}`;
const { data } = await got(link, {
headers: {
'user-agent': config.trueUA,
},
});
return {
title: lang === 'en' ? 'News' : 'Noticias',
link: `${baseUrl}/${lang}/news/news-filter-results`,
description: lang === 'en' ? "News from the official site of men's professional tennis." : 'Noticias del sitio oficial del tenis profesional masculino.',
language: lang,
icon: favIcon,
logo: favIcon,
author: 'ATP',
item: data.content.map((item) => ({
title: item.title,
link: baseUrl + item.url,
description: item.description,
author: item.byline,
category: item.category,
pubDate: parseDate(item.authoredDate),
image: baseUrl + item.image,
})),
};
}