Browse code

Merge branch 'pilif-github-repositories-plugin'

Brandon Mathis authored on 03/09/2011 at 15:04:25
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,30 @@
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
+  {% if site.github_show_profile_link %}
7
+  <a href="https://github.com/{{site.github_user}}">@{{site.github_user}}</a> on Github
8
+  {% endif %}
9
+  <script type="text/javascript">
10
+    $.domReady(function(){
11
+        if (!window.jXHR){
12
+            var jxhr = document.createElement('script');
13
+            jxhr.type = 'text/javascript';
14
+            jxhr.src = '{{ root_url}}/javascripts/libs/jXHR.js';
15
+            var s = document.getElementsByTagName('script')[0];
16
+            s.parentNode.insertBefore(jxhr, s);
17
+        }
18
+
19
+        github.showRepos({
20
+            user: '{{site.github_user}}',
21
+            count: {{site.github_repo_count}},
22
+            skip_forks: {{site.github_skip_forks}},
23
+            target: '#gh_repos'
24
+        });
25
+    });
26
+  </script>
27
+  <script src="{{ root_url }}/javascripts/github.js" type="text/javascript"> </script>
28
+</section>
29
+{% endif %}
0 30
new file mode 100644
... ...
@@ -0,0 +1,43 @@
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(options){
11
+            var feed = new jXHR();
12
+            feed.onerror = function (msg,url) {
13
+              $(options.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 (options.skip_forks && data.repositories[i].fork)
21
+                    continue;
22
+                  repos.push(data.repositories[i]);
23
+                }
24
+                repos.sort(function(a, b){
25
+                    var a = new Date(a.pushed_at),
26
+                        b = new Date(b.pushed_at);
27
+
28
+                    if (a.valueOf() == b.valueOf()) return 0;
29
+                    return a.valueOf() > b.valueOf() ? -1 : 1;
30
+                });
31
+
32
+                if (options.count)
33
+                    repos.splice(options.count);
34
+
35
+                render(options.target, repos)
36
+              }
37
+            };
38
+            feed.open("GET","http://github.com/api/v2/json/repos/show/"+options.user+"?callback=?");
39
+            feed.send();
40
+        }
41
+    };
42
+})();
0 43
\ No newline at end of file
... ...
@@ -36,7 +36,7 @@ excerpt_link: "Read on &rarr;"  # "Continue reading" link text at the bottom of
36 36
 
37 37
 # list each of the sidebar modules you want to include, in the order you want them to appear.
38 38
 # To add custom asides, create files in /source/_includes/custom/asides/ and add them to the list like 'custom/asides/custom_aside_name.html'
39
-default_asides: [asides/recent_posts.html, asides/twitter.html, asides/delicious.html, asides/pinboard.html]
39
+default_asides: [asides/recent_posts.html, asides/github.html, asides/twitter.html, asides/delicious.html, asides/pinboard.html]
40 40
 
41 41
 # Each layout uses the default asides, but they can have their own asides instead. Simply uncomment the lines below
42 42
 # and add an array with the asides you want to use.
... ...
@@ -48,6 +48,12 @@ default_asides: [asides/recent_posts.html, asides/twitter.html, asides/delicious
48 48
 #   3rd Party Settings    #
49 49
 # ----------------------- #
50 50
 
51
+# Github repositories
52
+github_user:
53
+github_repo_count: 0
54
+github_show_profile_link: true
55
+github_skip_forks: true
56
+
51 57
 # Twitter
52 58
 twitter_user:
53 59
 twitter_tweet_count: 4