/
index.ts
98 lines (89 loc) 路 1.76 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
95
96
97
98
import { Route } from '@/types';
import { getData, getList, getRedirectedLink } from './utils.js';
const variables = {
version: 11,
ranking: 'POPULARITY',
first: 15,
};
const query = `
query AnonymousFeed(
$first: Int
$ranking: Ranking
$version: Int
$supportedTypes: [String!] = ["article","share","freeform"]
) {
page: anonymousFeed(
first: $first
ranking: $ranking
version: $version
supportedTypes: $supportedTypes
) {
...FeedPostConnection
}
}
fragment FeedPostConnection on PostConnection {
edges {
node {
...FeedPost
}
}
}
fragment FeedPost on Post {
...SharedPostInfo
}
fragment SharedPostInfo on Post {
id
title
image
readTime
permalink
summary
createdAt
numUpvotes
numComments
author {
...UserShortInfo
}
tags
}
fragment UserShortInfo on User {
id
name
image
permalink
username
bio
}
`;
const graphqlQuery = {
query,
variables,
};
export const route: Route = {
path: '/',
example: '/daily',
radar: [
{
source: ['daily.dev/popular'],
},
],
name: 'Popular',
maintainers: ['Rjnishant530'],
handler,
url: 'daily.dev/popular',
};
async function handler() {
const baseUrl = 'https://app.daily.dev/popular';
const data = await getData(graphqlQuery);
const list = getList(data);
const items = await getRedirectedLink(list);
return {
title: 'Popular',
link: baseUrl,
item: items,
description: 'Popular Posts on Daily.dev',
logo: 'https://app.daily.dev/favicon-32x32.png',
icon: 'https://app.daily.dev/favicon-32x32.png',
language: 'en-us',
};
}