-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
447 lines (420 loc) · 14.5 KB
/
index.html
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
/>
<style type="text/css">
.readme {
column-count: 2;
}
.readme .columns-breaker {
column-span: all;
text-align: center;
}
.readme h3[align="center"] {
padding-top:25px;
}
.readme blockquote {
font-family: Georgia, 'Times New Roman', Times, serif;
line-height: 160%;
font-style: italic;
letter-spacing: 0.05rem;
color: #5c5c5c;
border-left: 3px solid #ff6600;
}
.readme .error {
padding-top: 25px;
}
.release-info,
.readme {
border: 1px solid #888;
border-radius: 10px;
margin: auto;
margin-top: 10px;
margin-bottom: 10px;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
font-size: 16px;
color: #333;
max-width: 1270px;
}
.readme img {
width: calc(100% - 50px);
column-span: all;
display: block;
margin: 25px;
}
.release-info {
border-collapse: collapse;
border-collapse: separate;
}
.release-info .link-color,
.readme .link-color {
color: #ff6600;
}
.release-info a,
.readme a {
color: #ff6600;
}
.release-info .fas {
color: #888;
}
.release-info td {
padding: 25px;
}
.no-wrap {
white-space: nowrap;
}
.readme p,
.readme h1,
.readme h2,
.readme h3,
.readme h4,
.readme h5,
.readme h6 {
padding: 0;
margin: 0 25px 25px;
}
.readme h2 {
border-bottom: 1px solid #ddd;
padding-bottom: 10px;
padding-top: 45px;
text-align: center;
}
.readme p {
line-height: 156%;
}
.release-info h1,
.release-info h2,
.release-info h3,
.release-info h4,
.release-info h5,
.release-info h6,
.release-info p,
.readme h4,
.readme h5,
.readme h6,
.readme p {
font-size: 1rem;
}
.release-info .section-title {
text-align: center;
padding: 10px 25px 0;
}
.release-info .section-title h2 {
border-bottom: 1px solid #ddd;
margin: 0;
padding: 0;
padding-bottom: 15px;
}
.release-info .section-footer {
text-align: center;
padding: 0 25px 10px;
}
.release-info .section-footer p.old-releases-list {
border-top: 1px solid #ddd;
margin: 0;
padding: 0;
padding-top: 15px;
}
</style>
</head>
<body>
<div id="release">
<i class="fa-solid fa-spinner fa-spin-pulse"></i>
</div>
<div id="readme" class="readme">
<i class="fa-solid fa-spinner fa-spin-pulse"></i>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/showdown.min.js"></script>
<script src="identity/site/scripts/helper.js"></script>
<script type="text/javascript">
/*
* Produces a list with release downloadable files, based or their number, or a
* placeholder message in their lack.
*/
const smartListWrap = (items) => {
return items.length > 1
? `<p><i class="fas fa-file-download"></i> Files:</p>
<ul>
<li>${items.join("</li><li>")}
</ul>`
: items.length > 0
? `<p><i class="fas fa-file-download"></i> File:</p> ${items[0]}`
: `<p><i class="fas fa-triangle-exclamation"></i> No downloadable files found.</p>`;
};
/**
* Returns the first header (of whatever rank) found in the given `markdownText`,
* also converting it to HTML.
*/
const getFirstHeader = (markdownText) => {
const header = markdownText.match(/#+\s(.+)/g)?.shift() || [];
const helpers = new Helpers();
return helpers.resolveMarkDown(header);
};
/**
* Compares two given multi-part numeric strings, whatever the format, e.g., "1.5.47"
* and "-1_0_16_0" are both accepted (the former compares "greater than" the later).
* Also, the two string operands need not use the same format either.
*
* NOTES: This function is meant to be used as an argument for the Array.sort()
* method.
*
* @param a
* First multi-part numeric string to compare.
*
* @param b
* Second multi-part numeric string to compare.
*
* @return
* Positive integer if the `a` multi-part compares "greater than" the `b`
* multi-part; negative integer if `a` compares "less than" `b`; and 0 if they
* compare "equal".
*/
const multiPartComparison = (a, b) => {
var integers = /(\-?\d{1,})/g;
// Prepare A
var aSegments = a.match(integers);
if (aSegments === null) {
return 0;
}
var numASegments = aSegments.length;
if (numASegments === 0) {
return 0;
}
// Prepare B
var bSegments = b.match(integers);
if (bSegments === null) {
return 0;
}
var numBSegments = bSegments.length;
if (numBSegments === 0) {
return 0;
}
// Compare
var maxLength = Math.max(numASegments, numBSegments);
var i = 0;
var rawASegment, rawBSegment, aSegment, bSegment, delta;
for (i; i < maxLength; i++) {
rawASegment = aSegments[i];
rawBSegment = bSegments[i];
aSegment = parseInt(rawASegment);
bSegment = parseInt(rawBSegment);
delta = aSegment - bSegment;
if (delta !== 0) {
return delta;
}
}
// Fallback to longest operand if nothing else helps
var rawASegmentLen = rawASegment ? rawASegment.length : 0;
var rawBSegmentLen = rawBSegment ? rawBSegment.length : 0;
return rawASegmentLen - rawBSegmentLen;
};
/**
* Infers an OS name and icon based on the extension of the provided `filename`.
*/
const inferOS = (filename) => {
// Extract the file extension
var extension = filename.split(".").pop();
// Infer the OS based on the file extension
var osLabel, osIcon;
switch (extension) {
case "exe":
osLabel = "Windows";
osIcon = "fab fa-windows";
break;
case "dmg":
case "pkg":
osLabel = "macOs";
osIcon = "fab fa-apple";
break;
default:
osLabel = "OS unknown";
osIcon = "fas fa-question-circle";
break;
}
// Return an object with the extension, OS label, and OS icon
return {
extension: extension,
osLabel: osLabel,
osIcon: osIcon,
};
};
// MAIN
// Get information about the latest release
const numPastReleasesToShow = 2;
fetch("https://api.github.com/repos/ciacob/maidens/releases")
.then((response) => {
if (!response.ok) {
console.log(response);
throw new Error(`HTTP Error while trying to access GitHub API. Details:
status: ${response.status},
statusText: ${response.statusText || "<EMPTY_STRING>"},
type: ${response.type},
url: ${response.url}
`);
}
return response.json();
})
.then((releases) => {
// Sort the releases in reverse chronological order
releases.sort((a, b) => multiPartComparison(b.tag_name, a.tag_name));
// Extract the latest release and the past three releases
const latestRelease = releases[0];
const pastReleases = releases.slice(1, numPastReleasesToShow + 1);
const numDeltaReleases = Math.max(
0,
releases.length - (pastReleases.length + 1)
);
// Extract the release details for the latest release
const latestVersion = latestRelease.tag_name;
const latestDate = new Date(
latestRelease.published_at
).toDateString();
const latestName = latestRelease.name;
const latestDescription = latestRelease.body;
const latestMoreInfo = getFirstHeader(latestDescription);
const latestAssets = latestRelease.assets.map((asset) => {
const fileInfo = inferOS(asset.name);
return `<span class="no-wrap"><i class="link-color ${fileInfo.osIcon}"></i>
<a href="${asset.browser_download_url}" title="${fileInfo.osLabel}">
${asset.name}
</a></span>`;
});
const latestUrl = latestRelease.html_url;
// Prepare the past releases list
const pastReleaseLinks = pastReleases.map(
(release) => `<i class="fas fa-tag"></i>
<a target="_blank" href="${release.html_url}">
${release.tag_name}
</a>`
);
if (numDeltaReleases) {
pastReleaseLinks.push(
`<i class="fas fa-arrow-up-right-from-square"></i>
<a target="_blank" href="https://github.com/ciacob/maidens/releases">
see all (${numDeltaReleases} more ${
numDeltaReleases > 1 ? "releases" : "release"
})
</a>`
);
}
// Update the 'release' div
document.getElementById("release").innerHTML = `
<table class="release-info">
<tr>
<td colspan="3" class="section-title">
<h2>Latest Release:</h2>
</td>
</tr>
<tr>
<td>
<p><i class="fas fa-tag"></i> Version:</p>
<p><strong>${latestVersion}</strong></p>
<p><i class="fas fa-calendar-alt"></i> Date:</p>
<p class="no-wrap"><strong>${latestDate}</strong></p>
</td>
<td class="more-info">
<p><i class="fas fa-clipboard-list"></i> Summary:</p>
<p><strong> ${latestName}</strong></p>
<p><i class="fas fa-circle-info"></i> More information:</p>
${latestMoreInfo}
<p class="learn-more">
<a href="${latestUrl}" target="_blank">Learn more</a>
</p>
</td>
<td>
${smartListWrap(latestAssets)}
</td>
</tr>
<tr>
<td colspan="3" class="section-footer">
<p class="old-releases-list">Past releases:
${pastReleaseLinks.join(" ")}
</p>
</td>
</tr>
</table>
`;
})
.catch((error) => {
console.error(
"Getting latest release failed: there was a problem with your fetch operation.",
error
);
document.getElementById("release").innerHTML = `
<table class="release-info error columns-breaker">
<tr>
<td colspan="3" class="section-footer">
<p><i class="fas fa-2xl fa-triangle-exclamation"></i></p>
<p>It seems there's a problem accessing the GitHub Releases API at the moment. </p>
<p>Please visit the
<i class="fas fa-arrow-up-right-from-square"></i>
<a target="_blank" href="https://github.com/ciacob/maidens/releases">releases page</a>
to check out the latest release.
</p>
</td>
</tr>
</table>
`;
});
// Retrieve the content in README.md and insert it in page as HTML
fetch("https://api.github.com/repos/ciacob/maidens/readme")
.then((response) => {
if (!response.ok) {
console.log(response);
throw new Error(`HTTP Error while trying to access GitHub API. Details:
status: ${response.status},
statusText: ${response.statusText || "<EMPTY_STRING>"},
type: ${response.type},
url: ${response.url}
`);
}
return response.json();
})
.then((readme) => {
// Decode the Base64 content
const rawMarkdown = new TextDecoder().decode(
Uint8Array.from(atob(readme.content), (c) => c.charCodeAt(0))
);
// Convert the markdown to HTML
const converter = new showdown.Converter();
const html = converter.makeHtml(rawMarkdown);
// Create a temporary div to manipulate the HTML
const tempDiv = document.createElement("div");
tempDiv.innerHTML = html;
// Add the 'columns-breaker' class to all H1-H3 and the very first paragraph.
tempDiv.querySelectorAll("h1, h2, h3").forEach((h) => {
h.classList.add("columns-breaker");
});
var paragraphs = tempDiv.querySelectorAll('p');
var firstParagraph = paragraphs[1]; // paragraph at index `0` holds an image.
firstParagraph.classList.add("columns-breaker");
// Insert the modified HTML into your page
document.getElementById("readme").innerHTML = tempDiv.innerHTML;
})
.catch((error) => {
console.error(
"Getting the `README.md` page content failed: there was a problem with your fetch operation.",
error
);
document.getElementById("readme").innerHTML = `
<table class="release-info error columns-breaker">
<tr>
<td colspan="3" class="section-footer">
<p><i class="fas fa-2xl fa-triangle-exclamation"></i></p>
<p>It seems there's a problem accessing the GitHub Readme API at the moment. </p>
<p>Please visit the project's
<i class="fas fa-arrow-up-right-from-square"></i>
<a target="_blank" href="https://github.com/ciacob/maidens">home page</a>
to retrieve this content there, instead.
</p>
</td>
</tr>
</table>
`;
});
</script>
</body>
</html>