From ff944a092da4094469735851aca606881463170e Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Mon, 7 Feb 2011 13:18:45 +0100 Subject: [PATCH] added language statistics (+ indentation and code formatting) --- js/githubresume.js | 60 ++++++++++++++++++++++++++++++++++++---------- views/job.html | 2 +- views/repo.html | 5 +++- views/resume.html | 37 ++++++++++++++-------------- 4 files changed, 70 insertions(+), 34 deletions(-) diff --git a/js/githubresume.js b/js/githubresume.js index c710b24..2b4c013 100644 --- a/js/githubresume.js +++ b/js/githubresume.js @@ -6,8 +6,9 @@ var urlParams = {}; d = function (s) { return decodeURIComponent(s.replace(a, " ")); }, q = window.location.search.substring(1); - while (e = r.exec(q)) + while (e = r.exec(q)) { urlParams[0] = d(e[1]); + } })(); var username; @@ -26,7 +27,7 @@ $(document).ready(function() { } catch (e) { /*fail silently*/ } - } + } }); var error = function() { @@ -54,8 +55,8 @@ var home = function() { var run = function() { var gh_user = gh.user(username); - var itemCount = 0, maxItems = 5; - + var itemCount = 0, maxItems = 5, maxLanguages = 5; + var res = gh_user.show(function(data) { gh_user.repos(function(data) { repos = data; @@ -77,7 +78,7 @@ var run = function() { } var view = { - name: name, + name: name, email: data.user.email, created_at: data.user.created_at, location: data.user.location, @@ -108,9 +109,17 @@ var run = function() { var repos = data.repositories; var sorted = []; - var languages = []; + var languages = {}; repos.forEach(function(elm, i, arr) { + if (arr[i].language) { + if (arr[i].language in languages) { + languages[arr[i].language]++; + } else { + languages[arr[i].language] = 1; + } + } + if (arr[i].fork !== false) { return; } @@ -118,19 +127,43 @@ var run = function() { var popularity = arr[i].watchers + arr[i].forks; sorted.push({position: i, popularity: popularity, info: arr[i]}); }); - + function sortByPopularity(a, b) { return b.popularity - a.popularity; }; sorted.sort(sortByPopularity); - + + function sortLanguages(languages, limit) { + var sorted_languages = []; + for (var lang in languages) { + if (typeof(lang) !== "string") { + continue; + } + sorted_languages.push({ + name: lang, + popularity: languages[lang], + toString: function() { + return '' + this.name + ''; + } + }); + } + if (limit) { + sorted_languages = sorted_languages.slice(0, limit); + } + return sorted_languages.sort(sortByPopularity); + } + $.ajax({ url: 'views/job.html', dataType: 'html', success: function(response) { var now = new Date().getFullYear(); + if (languages) { + $('#languages').html('I mostly program in ' + sortLanguages(languages, maxLanguages).join(', ') + '.'); + } + if (sorted.length > 0) { $('#jobs').html(''); itemCount = 0; @@ -138,7 +171,7 @@ var run = function() { if (itemCount >= maxItems) { return; } - + var since = new Date(arr[index].info.created_at); since = since.getFullYear(); @@ -146,19 +179,20 @@ var run = function() { name: arr[index].info.name, since: since, now: now, + language: arr[index].info.language, description: arr[index].info.description, username: username, watchers: arr[index].info.watchers, forks: arr[index].info.forks }; - + if (itemCount == sorted.length - 1 || itemCount == maxItems-1) { view.last = 'last'; } var template = response; var html = Mustache.to_html(template, view); - + $('#jobs').append($(html)); ++itemCount; @@ -200,13 +234,13 @@ var run = function() { login: arr[index].info.login, now: now }; - + if (itemCount == sorted.length - 1 || itemCount == maxItems) { view.last = 'last'; } var template = response; var html = Mustache.to_html(template, view); - + $('#orgs').append($(html)); ++itemCount; }); diff --git a/views/job.html b/views/job.html index d51b1a2..8a988c0 100644 --- a/views/job.html +++ b/views/job.html @@ -2,7 +2,7 @@

{{name}}

-

Creator & Owner

+

{{#language}}{{language}} - {{/language}}Creator & Owner

{{since}} - {{now}}

{{description}}.

diff --git a/views/repo.html b/views/repo.html index a9b6e74..3655710 100644 --- a/views/repo.html +++ b/views/repo.html @@ -1,4 +1,7 @@ {{#repo}} -

{{repo}}

+
+

{{repo}}

+

{{language}}

+

{{description}}

{{/repo}} diff --git a/views/resume.html b/views/resume.html index 3b3dd19..ab4430e 100644 --- a/views/resume.html +++ b/views/resume.html @@ -1,6 +1,6 @@
- +
@@ -31,21 +31,21 @@

- I'm a developer - {{#location}} - based in {{location}} - {{/location}} - with {{repos}} public {{plural}}. - I've been using github.com since {{since}} - {{#blog}} - and sometimes I blog at {{blog}} - {{/blog}} + I'm a developer + {{#location}} + based in {{location}} + {{/location}} + with {{repos}} public {{plural}}. + I've been using github.com since {{since}} + {{#blog}} + and sometimes I blog at {{blog}}. + {{/blog}}

+

- -
+

My Popular Repositories

@@ -54,7 +54,8 @@ Loading information...
-
+ +

My Organizations

@@ -64,17 +65,16 @@
-

About This Résumé

- This résumé is generated automatically using information from my github account. The repositories are - ordered by popularity based on a very simple popularity heuristic that defines the popularity of a repository - by its sum of watchers and forks. Do not hesitate to visit my github page - for more information about my repositories and work. + This résumé is generated automatically using information from my github account. The repositories are + ordered by popularity based on a very simple popularity heuristic that defines the popularity of a repository + by its sum of watchers and forks. Do not hesitate to visit my github page + for more information about my repositories and work.

@@ -88,7 +88,6 @@
-