|
1 | | -// ------------------------------------------- |
2 | | -// Author: Seyon Rajagopal |
3 | | -// Copyright (c) 2022 Seyon Rajagopal |
4 | | -// ------------------------------------------- |
5 | | - |
6 | 1 | async function latest_release(repo_name) { |
7 | 2 | const response = await fetch(`https://api.github.com/repos/qlibs/${repo_name}/releases/latest`); |
8 | 3 | const data = await response.json(); |
9 | 4 | return data.tag_name; |
10 | 5 | } |
11 | 6 |
|
12 | 7 | window.onload = function () { |
13 | | - var request = $.get('https://api.github.com/users/qlibs/repos', function () { }) |
14 | | - .done(function () { |
15 | | - request = request.responseJSON; |
16 | | - if (!Array.isArray(request) || !request.length) { |
17 | | - $("#repo-box").append("<div class='error-box'><h1 class='error-msg'> Sorry the GitHub username entered has no repos or does't exist </h1></div>"); |
18 | | - } |
19 | | - else { |
20 | | - for (i = 0; i < request.length; i++) { |
21 | | - const repo_name = request[i].name; |
22 | | - if (repo_name.includes("github.io")) continue; |
23 | | - if (repo_name.includes("qlibs")) continue; |
24 | | - if (repo_name.includes(".github")) continue; |
25 | | - const repo_url = request[i].html_url; |
26 | | - const repo_description = request[i].description; |
27 | | - const repo_stars = request[i].stargazers_count; |
28 | | - const repo_forks = request[i].forks; |
29 | | - latest_release(repo_name).then(repo_release => { |
30 | | - $("#repo-box").append( |
31 | | - "<a href='" + repo_url + "'><div class='repo-item'><h1 class='title'>" + repo_name + "</h1>" + |
32 | | - "<p class='description'>" + repo_description + |
33 | | - "<div class='star'><span class='img' uk-icon='star' class='uk-icon'></span>" + repo_stars + "</div>" + |
34 | | - "<div class='fork'><span class='img' uk-icon='git-fork' class='uk-icon'></span>" + (repo_release === undefined ? "-" : repo_release) + "</div>" + |
35 | | - "</div></div></p>" |
36 | | - ); |
37 | | - }) |
38 | | - } |
39 | | - } |
40 | | - }); |
41 | | -} |
| 8 | + (async function update() { |
| 9 | + const response = await $.get('https://api.github.com/users/qlibs/repos'); |
| 10 | + |
| 11 | + if (!Array.isArray(response) || !response.length) { |
| 12 | + return; |
| 13 | + } |
| 14 | + |
| 15 | + const filtered = response |
| 16 | + .filter(repo => { |
| 17 | + const name = repo.name.toLowerCase(); |
| 18 | + return !(name.includes("github") || name.includes("qlibs")); |
| 19 | + }) |
| 20 | + .sort((a, b) => a.name.localeCompare(b.name)); |
| 21 | + |
| 22 | + for (const repo of filtered) { |
| 23 | + const repo_name = repo.name; |
| 24 | + const repo_description = repo.description || ""; |
| 25 | + const repo_stars = repo.stargazers_count; |
| 26 | + const repo_forks = repo.forks; |
| 27 | + const repo_url = repo.html_url; |
| 28 | + const repo_release = await latest_release(repo_name).catch(() => "-"); |
| 29 | + |
| 30 | + $("#repo-box").append( |
| 31 | + `<a href="${repo_url}"> |
| 32 | + <div class='repo-item'> |
| 33 | + <h1 class='title'>${repo_name}</h1> |
| 34 | + <p class='description'>${repo_description}</p> |
| 35 | + <div class='star'><span class='img' uk-icon='star'></span> ${repo_stars}</div> |
| 36 | + <div class='fork'><span class='img' uk-icon='git-fork'></span> ${repo_release || '-'}</div> |
| 37 | + </div> |
| 38 | + </a>` |
| 39 | + ); |
| 40 | + } |
| 41 | + })(); |
| 42 | +}; |
0 commit comments