Browse code

add github repositories sidebar plugin

if you specify

github_user:

in you _config.yml and once you add asides/github.html to your sidebar
items, this plugin will fetch the specified users github repositories
and order them so the last pushed ones are shown first. Then it'll list
them in the side-bar, including a link and the repository description

The plugin will only list your own repositories, not forks, though this
might need to be configurable later

Philip Hofstetter authored on 04/08/2011 at 18:59:29
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+{% if site.github_user %}
1
+<section>
2
+  <h1>Github Repos</h1>
3
+  <ul id="gh_repos">
4
+    <li class="loading">Status updating...</li>
5
+  </ul>
6
+  <script type="text/javascript">
7
+    $.domReady(function(){
8
+        if (!window.jXHR){
9
+            var jxhr = document.createElement('script');
10
+            jxhr.type = 'text/javascript';
11
+            jxhr.src = '{{ root_url}}/javascripts/libs/jXHR.js';
12
+            var s = document.getElementsByTagName('script')[0];
13
+            s.parentNode.insertBefore(jxhr, s);
14
+        }
15
+        github.showRepos('{{site.github_user}}', '#gh_repos');
16
+    });
17
+  </script>
18
+  <script src="{{ root_url }}/javascripts/github.js" type="text/javascript"> </script>
19
+</section>
20
+{% endif %}
0 21
new file mode 100644
... ...
@@ -0,0 +1,38 @@
0
+github = (function(){
1
+    function render(target, repos){
2
+        var i = 0, fragment = '', t = $(target)[0];
3
+
4
+        for(i = 0; i < repos.length; i++)
5
+            fragment += '<li><a href="'+repos[i].url+'">'+repos[i].name+'</a><p>'+repos[i].description+'</p></li>';
6
+
7
+        t.innerHTML =  fragment;
8
+    }
9
+    return {
10
+        showRepos: function(user, target){
11
+            var feed = new jXHR();
12
+            feed.onerror = function (msg,url) {
13
+              $(target + ' li.loading').addClass('error').text("Error loading feed");
14
+            }
15
+            feed.onreadystatechange = function(data){
16
+              if (feed.readyState === 4) {
17
+                var repos = [];
18
+                var i;
19
+                for (i = 0; i < data.repositories.length; i++){
20
+                  if (!data.repositories[i].fork)
21
+                    repos.push(data.repositories[i]);
22
+                }
23
+                repos.sort(function(a, b){
24
+                    var a = new Date(a.pushed_at),
25
+                        b = new Date(b.pushed_at);
26
+
27
+                    if (a.valueOf() == b.valueOf()) return 0;
28
+                    return a.valueOf() > b.valueOf() ? -1 : 1;
29
+                })
30
+                render(target, repos)
31
+              }
32
+            };
33
+            feed.open("GET","http://github.com/api/v2/json/repos/show/"+user+"?callback=?");
34
+            feed.send();
35
+        }
36
+    };
37
+})();
0 38
\ No newline at end of file
... ...
@@ -55,6 +55,9 @@ twitter_follow_button: true
55 55
 twitter_show_follower_count: false
56 56
 twitter_tweet_button: true
57 57
 
58
+# github repositories
59
+github_user:
60
+
58 61
 # Google Plus
59 62
 google_plus_one: true
60 63
 google_plus_one_size: medium