Skip to content

Commit

Permalink
Sort projects by # of watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jan 27, 2012
1 parent 7096197 commit 9a29fcf
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions assets/application.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
(function ($) {
function addRecentlyUpdatedRepo(repo) {
var $item = $("<li>");

$item.append('<span class="name"><a href="' + repo.html_url + '">' + repo.name + '</a></span>');
$item.append('<span class="time"><a href="' + repo.html_url + '/commits">' + strftime("%h %e, %Y", repo.pushed_at) + '</a></span>');
$item.append('<span class="bullet">&sdot;</span>');
$item.append('<span class="watchers"><a href="' + repo.html_url + '/watchers">' + repo.watchers + ' watchers</a></span>');
$item.append('<span class="bullet">&sdot;</span>');
$item.append('<span class="forks"><a href="' + repo.html_url + '/network">' + repo.forks + ' forks</a></span>');

$item.appendTo("#recently-updated-repos");
}

function addProject(project) {
var $project = $("<div />").addClass("project");
var $project = $("<div>").addClass("project");
$project.addClass(project.language);
$project.append($("<h2 />").text(project.name));
$project.append($("<h3 />").text(project.language));
$project.append($("<p />").text(project.description));
$project.append($("<h2>").text(project.name));
$project.append($("<h3>").text(project.language));
$project.append($("<p>").text(project.description));
$project.appendTo("#projects");
}

Expand All @@ -32,17 +30,24 @@
repo.pushed_at = new Date(repo.pushed_at);
});

// Sort by most-recently pushed to.
// Sort by most # of watchers.
repos.sort(function (a, b) {
if (a.pushed_at < b.pushed_at) return 1;
if (b.pushed_at < a.pushed_at) return -1;
if (a.watchers < b.watchers) return 1;
if (b.watchers < a.watchers) return -1;
return 0;
});

$.each(repos, function(i, repo){
$.each(repos, function (i, repo) {
addProject(repo);
});

// Sort by most-recently pushed to.
repos.sort(function (a, b) {
if (a.pushed_at < b.pushed_at) return 1;
if (b.pushed_at < a.pushed_at) return -1;
return 0;
});

$.each(repos.slice(0, 3), function (i, repo) {
addRecentlyUpdatedRepo(repo);
});
Expand Down

0 comments on commit 9a29fcf

Please sign in to comment.