/
apod-cn.ts
52 lines (48 loc) · 1.47 KB
/
apod-cn.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 got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/apod-cn',
categories: ['picture'],
example: '/nasa/apod-cn',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['apod.nasa.govundefined'],
},
],
name: 'NASA 中文',
maintainers: ['nczitzk', 'williamgateszhao'],
handler,
url: 'apod.nasa.govundefined',
description: `:::tip
[NASA 中文](https://www.nasachina.cn/) 提供了每日天文图的中英双语图文说明,但在更新上偶尔略有一两天的延迟。
:::`,
};
async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10;
const rootUrl = `https://www.nasachina.cn/wp-json/wp/v2/posts?categories=2&per_page=${limit}`;
const { data } = await got({
method: 'get',
url: rootUrl,
});
const items = data.map((item) => ({
title: item.title.rendered,
description: item.content.rendered,
pubDate: parseDate(item.date_gmt),
link: item.link,
}));
return {
title: 'NASA中文 - 天文·每日一图',
link: 'https://www.nasachina.cn/nasa-image-of-the-day',
item: items,
};
}