Skip to content

Commit cf0bedf

Browse files
committed
Update link.js
1 parent bb2e7a8 commit cf0bedf

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

api/link.js

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
11

2-
export default function handler(request, response) {
2+
export default async function handler(request, response) {
33

44
const query = request.query;
55

66
let title = 'Codeit | Mobile code editor connected to Git';
7-
7+
let desc = 'Run JavaScript projects, code your ideas, and share it all on Codeit.';
8+
let twitterTitle = false;
9+
10+
11+
12+
function getRequest(url) {
13+
14+
return new Promise(resolve => {
15+
16+
const req = https.get(url, (resp) => {
17+
18+
let data = '';
19+
20+
resp.on('data', (chunk) => {
21+
22+
data += chunk;
23+
24+
});
25+
26+
resp.on('end', () => {
27+
28+
resolve({status: resp.statusCode, data: data});
29+
30+
});
31+
32+
});
33+
34+
});
35+
36+
}
37+
38+
39+
840
if (query.url) {
941

1042
// parse URL
@@ -23,20 +55,34 @@ export default function handler(request, response) {
2355

2456
}
2557

58+
59+
const repoName = url[0] + '/' + url[1].split(':')[0];
60+
61+
62+
const {status, resp} = await getRequest('https://api.github.com/repos/' + repoName);
63+
64+
const repoDesc = JSON.parse(resp).description;
65+
66+
if (repoDesc) desc = repoDesc;
67+
else desc = '';
68+
69+
2670
if (url[url.length-1].endsWith('.html')
2771
|| url[url.length-1].endsWith('.svg')) {
2872

29-
title = 'Run ' + url[0] + '/' + url[1].split(':')[0] + ' with Codeit';
73+
title = 'Run ' + repoName + ' on Codeit';
3074

3175
} else {
3276

33-
title = 'Open ' + url[0] + '/' + url[1].split(':')[0] + ' with Codeit';
77+
title = repoName + ' on Codeit';
3478

3579
}
3680

3781
}
3882

3983
}
84+
85+
if (!twitterTitle) twitterTitle = title;
4086

4187

4288

@@ -56,25 +102,25 @@ const html = `
56102
<meta name="apple-mobile-web-app-title" content="Codeit">
57103
58104
<meta charset="utf-8">
59-
<!-- <meta name="description" content="Run JavaScript projects, code your ideas, and share it all on Codeit."> -->
105+
<meta name="description" content="`+ desc +`">
60106
61107
<meta property="og:title" content="`+ title +`">
62-
<!-- <meta property="og:description" content="Run JavaScript projects, code your ideas, and share it all on Codeit."> -->
108+
<meta property="og:description" content="`+ desc +`">
63109
<meta property="og:url" content="https://codeit.codes">
64110
<meta property="og:image" content="https://codeit.codes/images/banner-og.png">
65111
<meta property="og:type" content="video.other">
66112
<meta property="og:site_name" content="Codeit">
67113
<meta property="og:video:url" content="https://codeit.codes/api/link?url=`+ query.url +`">
68114
<meta property="og:video:secure_url" content="https://codeit.codes/api/link?url=`+ query.url +`">
69115
<meta property="og:video:type" content="text/html">
70-
<meta property="og:video:width" content="1280">
116+
<meta property="og:video:width" content="128'https://api.github.com/repos/' + 0">
71117
<meta property="og:video:height" content="720">
72118
73-
<meta property="twitter:title" content="`+ title +`">
119+
<meta property="twitter:title" content="`+ twitterTitle +`">
74120
<meta property="twitter:site" content="@codeitcodes">
75121
<meta name="twitter:card" content="player">
76122
<meta property="twitter:domain" content="https://codeit.codes/">
77-
<!-- <meta name="twitter:description" content="Run JavaScript projects, code your ideas, and share it all on Codeit."> -->
123+
<meta name="twitter:description" content="`+ desc +`">
78124
<meta name="twitter:image" content="https://codeit.codes/images/banner-og.png">
79125
<meta name="twitter:player" content="https://codeit.codes/api/link?url=`+ query.url +`">
80126
<meta name="twitter:player:stream:content_type" content="text/html">

0 commit comments

Comments
 (0)