Browse code

Merge branch 'github-repositories-plugin' of https://github.com/pilif/octopress into pilif-github-repositories-plugin

Brandon Mathis authored on 03/09/2011 at 14:09:15
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
... ...
@@ -56,6 +56,12 @@ twitter_follow_button: true
56 56
 twitter_show_follower_count: false
57 57
 twitter_tweet_button: true
58 58
 
59
+# github repositories
60
+github_user:
61
+github_repo_count: 0
62
+github_show_profile_link: true
63
+github_skip_forks: true
64
+
59 65
 # Google Plus
60 66
 google_plus_one: true
61 67
 google_plus_one_size: medium