-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
321 lines (227 loc) · 10.3 KB
/
index.html
File metadata and controls
321 lines (227 loc) · 10.3 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GitHub Card Generator</title>
<link rel="icon" type="image/x-icon" href="assets/favicon.ico">
<meta name="description"
content="A fan-made generator for cards to display github repositories. Download your cards in PNG or copy the code to your website!">
<meta name="author" content="immarianaas">
<meta http-equiv="Permissions-Policy" content="interest-cohort=()">
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-html.js"></script>
<script src="scripts/script.js" type="text/javascript"></script>
<script type="module">
import { Octokit } from "https://cdn.skypack.dev/@octokit/rest";
let octokit = new Octokit({});
let owner = "immarianaas";
let repo = "github-card-generator";
function updateCard(owner, repo) {
let answer = octokit.request('GET /repos/' + owner + '/' + repo, {
owner: owner,
repo: repo
});
answer.then(result => {
console.log(result);
let data = result.data;
document.getElementById('owner').textContent = data.owner.login;
document.getElementById('repo-name').textContent = data.name;
document.getElementById('description').textContent = data.description;
document.getElementById('owneravatar').src = data.owner.avatar_url;
let noPropFunc = "event.stopPropagation();";
let openRepoPageFunc = "window.open('https://github.com/" + owner + "/" + repo + "');"
document.getElementById('card').setAttribute("onclick", openRepoPageFunc);
let openUserPageFunc = "window.open('https://github.com/" + owner + "');" + noPropFunc;
document.getElementById('user-section').setAttribute("onclick", openUserPageFunc);
// cleanup topics
document.getElementById('topics').innerHTML = "";
let topicsLength = data.topics.length;
for (let i = 0; i < topicsLength; i++) {
// https://github.com/topics/
let topic_code = '<span id="topic' + i + '"></span>\n';
document.getElementById('topics').innerHTML += topic_code;
document.getElementById('topic' + i).textContent = data.topics[i];
}
// reset additonal info
document.getElementById('additional-info').innerHTML = "";
// [todo] add languages
if (data.license) {
document.getElementById('additional-info').innerHTML += '<div id="licence"></div>';
document.getElementById('licence').textContent = data.license.name;
}
let stargazers_url = 'https://github.com/' + owner + '/' + repo + '/stargazers';
let watchers_url = 'https://github.com/' + owner + '/' + repo + '/watchers';
let forks_url = 'https://github.com/' + owner + '/' + repo + '/network/members';
document.getElementById('additional-info').innerHTML += '<div class="underline-hover" onclick="window.open(\'' + stargazers_url + '\'); ' + noPropFunc + '"><b>' + data.stargazers_count + '</b> stargazers</div>\n';
document.getElementById('additional-info').innerHTML += '<div class="underline-hover" onclick="window.open(\'' + watchers_url + '\'); ' + noPropFunc + '"><b>' + data.subscribers_count + '</b> watchers</a></div>\n';
document.getElementById('additional-info').innerHTML += '<div class="underline-hover" onclick="window.open(\'' + forks_url + '\'); ' + noPropFunc + '"><b>' + data.forks_count + '</b> forks</a></div>\n';
}).catch( error => {
handleFormError();
});
}
window.onload = function () {
resetPage();
updateCard(owner, repo);
}
function onSubmitForm() {
let form = document.getElementById('form');
let formData = new FormData(form);
owner = formData.get('username').trim();
repo = formData.get('repository').trim();
updateCard(owner, repo);
resetPage();
}
function onClickCard() {
window.open('https://github.com/' + owner + '/' + repo);
}
function onClickUser() {
window.open('https://github.com/' + owner);
}
window.onSubmitForm = onSubmitForm;
window.onClickCard = onClickCard;
window.onClickUser = onClickUser;
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css">
<script type="module">
import hljs from 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/es/highlight.min.js';
hljs.highlightAll();
const escapeHtml = (unsafe) => {
return unsafe.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
}
function genStaticHtml() {
const options = { indent_size: 2 }
let card = document.getElementById('card');
let beautified_code = html_beautify(card.outerHTML, options);
let codeblock = document.getElementById('html-code-block');
codeblock.innerHTML = escapeHtml(beautified_code);
hljs.highlightElement(codeblock);
let cssblock = document.getElementById('css-code-block');
let beautified_css = css_beautify(cssCode, options);
cssblock.innerHTML = beautified_css;
hljs.highlightElement(cssblock);
showCodeSection();
}
window.genStaticHtml = genStaticHtml;
</script>
<script>
function convertToImage() {
var node = document.getElementById('card');
domtoimage.toPng(node, {
style: {
'margin-top': '0px'
}
})
.then(function (dataUrl) {
const link = document.createElement('a')
link.href = dataUrl
link.download = 'gh-card'
document.body.appendChild(link)
link.click()
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
}
</script>
<script src="scripts/dom-to-image.js"></script>
<!-- Link to your CSS file -->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/card-style.css">
</head>
<body>
<!------------------ FORM PART ------------------>
<div class="form">
<div id="title">
GitHub Card Generator
</div>
<div>
Fan-made. To learn more click on the card!
</div>
<form id="form" action="" onsubmit="onSubmitForm(); return false">
<div>
<div><label for="username">Username:</label></div>
<div><input class="textInput" type="text" name="username" id="username" value="" placeholder="immarianaas">
</div>
</div>
<div style="margin-top: 30px;">
<div><label for="repository">Repository name:</label></div>
<div><input class="textInput" type="text" name="repository" id="repository" value=""
placeholder="github-card-generator"></div>
</div>
<input class="submitBtn blue" type="submit" value="Generate card!" />
</form>
<div id="error-msg" hidden>
<p> Hmmm... </p>
<p> There was an error with the request.
Probably the repository doesn't exist. </p>
<p> Can you please check the input again? :) </p>
</div>
</div>
<!------------------ CARD PART ------------------>
<div class="cardsection">
<div class="container">
<div id="card-container">
<!-------------------------------- part that needs to be pretty --------------------------------->
<div id="card" class="pointer-cursor">
<!-- title & header part -->
<!-- * github icon -->
<div class="icon">
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="40px">
<title>GitHub</title>
<path
d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" />
</svg>
</div>
<!-- * user section -->
<div id="user-section">
<img id="owneravatar" width="40px" class="icon">
<div id="owner"></div>
</div>
<!-- * repository name -->
<div id="repo-name"></div>
<p id="description"></p>
<div id="topics">
<!-- if there are topics, they will appear here -->
</div>
<div id="additional-info"></div>
</div>
<!-------------------------------- part that needs to be pretty ^ --------------------------------->
</div>
<div></div>
<button class="submitBtn pink" onclick="genStaticHtml()"> show static HTML & CSS code
</button>
<button class="submitBtn pink" onclick="convertToImage()"> download PNG
</button>
</div>
<div id="codeSection">
<div class="htmlContainer">
<div class="codeBlock">
<div class="codeHeader">
<button class="copy" onclick="copyHTMLCode()">copy to clipboard</button>
<span id="html-copiedMsg">copied!</span>
</div>
<div style="display: block; height: 5px;"></div>
<pre>
<code class="html" id="html-code-block">
</code>
</pre>
</div>
</div>
<div class="cssContainer">
<div class="codeBlock">
<div class="codeHeader">
<button class="copy" onclick="copyCSSCode()">copy to clipboard</button>
<span id="css-copiedMsg" hidden>copied!</span>
</div>
<div style="display: block; height: 5px;"></div>
<pre>
<code class="css" id="css-code-block">
</code>
</pre>
</div>
</div>
</div>
</div>
</body>
</html>