-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlink.js
More file actions
184 lines (109 loc) · 5.64 KB
/
link.js
File metadata and controls
184 lines (109 loc) · 5.64 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
export default function handler(request, response) {
const query = request.query;
let title = 'Codeit | Mobile code editor connected to Git';
if (query.url) {
// parse URL
let url = query.url.replace('https://cde.run/', '')
.replace('https://dev.cde.run/', '')
.replace('https://github.com/', '')
.replace('https:/github.com/', '');
let [user, repo] = url.split('/');
if (user && repo) {
if (repo.endsWith('.git')) {
repo = repo.slice(0, -('.git'.length));
}
const repoName = user + '/' + repo.split(':')[0];
if (url.endsWith('.html') ||
url.endsWith('.svg')) {
title = 'Run ' + repoName + ' on Codeit';
} else {
title = repoName + ' on Codeit';
}
}
}
const html = `
<!DOCTYPE html>
<html style="background: #313744" translate="no">
<head>
<title>Codeit</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover,shrink-to-fit=no">
<meta name="mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#313744">
<meta name="apple-mobile-web-app-status-bar-style" content="#313744">
<meta name="apple-mobile-web-app-title" content="Codeit">
<meta charset="utf-8">
<meta name="description" content="">
<meta property="og:title" content="`+ title +`">
<meta property="og:description" content="">
<meta property="og:url" content="https://codeit.codes">
<meta property="og:image" content="https://codeit.codes/images/banner-og.png">
<meta property="og:type" content="video.other">
<meta property="og:site_name" content="Codeit">
<meta property="og:video:url" content="https://codeit.codes/api/link?url=`+ query.url +`">
<meta property="og:video:secure_url" content="https://codeit.codes/api/link?url=`+ query.url +`">
<meta property="og:video:type" content="text/html">
<meta property="og:video:width" content="1280">
<meta property="og:video:height" content="720">
<meta property="twitter:title" content="`+ title +`">
<meta property="twitter:site" content="@codeitcodes">
<meta name="twitter:card" content="player">
<meta property="twitter:domain" content="https://codeit.codes/">
<meta name="twitter:description" content="">
<meta name="twitter:image" content="https://codeit.codes/images/banner-og.png">
<meta name="twitter:player" content="https://codeit.codes/api/link?url=`+ query.url +`">
<meta name="twitter:player:stream:content_type" content="text/html">
<meta name="twitter:player:width" content="800">
<meta name="twitter:player:height" content="600">
<link rel="alternate" type="application/json+oembed" href="https://codeit.codes/api/oembed?url=`+ query.url +`&format=json" title="`+ title +`">
<meta name="referrer" content="default">
<meta name="keywords" content="code editor, version control tools, source code versioning, source code management tools, python, jquery demo, html, git, how to, bootstrap, jquery, javascript, javascript tutorial, javascript tutorial for beginners, javascript programming, html web form, create form in html, responsive web design, html web design, html design, responsive website development, html5 tutorial, html5 css3, html5 development, web design software, web development software, git tutorial, git howto, git repository, git command, git source code, top programming languages to learn, best programming language, best computer language, open source, open source code, open source applications, source code editor, software development tools, development tool, software developer tools list, programmer tool, web application development software">
<link rel="canonical" href="https://codeit.codes/">
<meta name="next-head-count" content="24">
<meta name="robots" content="all">
<link rel="iframely player" type="text/html"
href="https://codeit.codes/api/link?url=`+ query.url +`"
media="(aspect-ratio: 1280/720)"/>
<link rel="shortcut icon" href="https://codeit.codes/icons/android-app-512.png">
<link rel="apple-touch-icon" href="https://codeit.codes/icons/iphone-app-180.png">
</head>
<body>
<script src="/api-link-parser.js"></script>
<script>
// decode link
const url = new URL(window.location.href).searchParams;
let link = url.get('url');
const notLiveView = (url.get('live') === 'false' || url.get('l') === 'f');
const isDev = (window.location.hostname === 'dev.codeit.codes');
if (link && link.startsWith('https://codeit.codes/api/link?url=')) {
link = link.replace('https://codeit.codes/api/link?url=', 'https://cde.run/');
}
if (link && link.includes('https:/github.com')) {
link = link.replace('https:/github.com', 'https://github.com');
}
if (link && !link.startsWith('https://cde.run')
&& !link.startsWith('https://dev.cde.run')) {
if (!isDev) link = 'https://cde.run/' + link;
else link = 'https://dev.cde.run/' + link;
}
if (link && link.startsWith('https://cde.run/github.com/')) {
link = link.replace('https://cde.run/github.com/', 'https://cde.run/https://github.com/');
}
if (link && link.startsWith('https://dev.cde.run/github.com/')) {
link = link.replace('https://dev.cde.run/github.com/', 'https://dev.cde.run/https://github.com/');
}
if (link && notLiveView) {
link += '?live=false';
}
if (link) {
const resp = decodeLink(link);
// redirect to decoded URL
window.location.replace(resp);
} else {
window.location.replace(window.location.origin);
}
</script>
</body>
</html>
`;
response.status(200).send(html);
}