Skip to content

Commit 9a29fcf

Browse files
committed
Sort projects by # of watchers
1 parent 7096197 commit 9a29fcf

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

assets/application.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
(function ($) {
22
function addRecentlyUpdatedRepo(repo) {
33
var $item = $("<li>");
4-
54
$item.append('<span class="name"><a href="' + repo.html_url + '">' + repo.name + '</a></span>');
65
$item.append('<span class="time"><a href="' + repo.html_url + '/commits">' + strftime("%h %e, %Y", repo.pushed_at) + '</a></span>');
76
$item.append('<span class="bullet">&sdot;</span>');
87
$item.append('<span class="watchers"><a href="' + repo.html_url + '/watchers">' + repo.watchers + ' watchers</a></span>');
98
$item.append('<span class="bullet">&sdot;</span>');
109
$item.append('<span class="forks"><a href="' + repo.html_url + '/network">' + repo.forks + ' forks</a></span>');
11-
1210
$item.appendTo("#recently-updated-repos");
1311
}
1412

1513
function addProject(project) {
16-
var $project = $("<div />").addClass("project");
14+
var $project = $("<div>").addClass("project");
1715
$project.addClass(project.language);
18-
$project.append($("<h2 />").text(project.name));
19-
$project.append($("<h3 />").text(project.language));
20-
$project.append($("<p />").text(project.description));
16+
$project.append($("<h2>").text(project.name));
17+
$project.append($("<h3>").text(project.language));
18+
$project.append($("<p>").text(project.description));
2119
$project.appendTo("#projects");
2220
}
2321

@@ -32,17 +30,24 @@
3230
repo.pushed_at = new Date(repo.pushed_at);
3331
});
3432

35-
// Sort by most-recently pushed to.
33+
// Sort by most # of watchers.
3634
repos.sort(function (a, b) {
37-
if (a.pushed_at < b.pushed_at) return 1;
38-
if (b.pushed_at < a.pushed_at) return -1;
35+
if (a.watchers < b.watchers) return 1;
36+
if (b.watchers < a.watchers) return -1;
3937
return 0;
4038
});
4139

42-
$.each(repos, function(i, repo){
40+
$.each(repos, function (i, repo) {
4341
addProject(repo);
4442
});
4543

44+
// Sort by most-recently pushed to.
45+
repos.sort(function (a, b) {
46+
if (a.pushed_at < b.pushed_at) return 1;
47+
if (b.pushed_at < a.pushed_at) return -1;
48+
return 0;
49+
});
50+
4651
$.each(repos.slice(0, 3), function (i, repo) {
4752
addRecentlyUpdatedRepo(repo);
4853
});

0 commit comments

Comments
 (0)