/
daily.ts
72 lines (61 loc) 路 2.02 KB
/
daily.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { rootUrl, apiRootUrl, processItems } from './util';
export const route: Route = {
path: '/daily',
categories: ['new-media'],
example: '/readhub/daily',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['readhub.cn/daily'],
},
],
name: '姣忔棩鏃╂姤',
maintainers: ['nczitzk', 'fashioncj'],
handler,
url: 'readhub.cn/daily',
};
async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 11;
const currentUrl = new URL('daily', apiRootUrl).href;
const infoUrl = new URL('daily', rootUrl).href;
const { data: currentResponse } = await got(currentUrl);
const dailyItems = currentResponse.data.items;
let items = dailyItems.slice(0, limit).map((item) => ({
title: item.title,
link: new URL(`topic/${item.uid}`, rootUrl).href,
description: `<p>${item.summary}</p>`,
guid: item.uid,
}));
items = await processItems(items, cache.tryGet);
const { data: currentHTMLResponse } = await got(infoUrl);
const $ = load(currentHTMLResponse);
const author = $('meta[name="application-name"]').prop('content');
const subtitle = $('meta[property="og:title"]').prop('content');
const image = 'https://readhub-oss.nocode.com/static/readhub.png';
const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl);
return {
item: items,
title: `${author} - ${subtitle}`,
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh',
image,
icon,
logo: icon,
subtitle,
author,
allowEmpty: true,
};
}