Last active
December 15, 2015 20:49
-
-
Save octaflop/5321567 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // From octopress: https://github.com/imathis/octopress/blob/master/.themes/classic/source/_includes/asides/github.html | |
| {% if site.github_user %} | |
| <section> | |
| <h1>GitHub Repos</h1> | |
| <ul id="gh_repos"> | |
| <li class="loading">Status updating...</li> | |
| </ul> | |
| {% if site.github_show_profile_link %} | |
| <a href="https://github.com/{{site.github_user}}">@{{site.github_user}}</a> on GitHub | |
| {% endif %} | |
| <script type="text/javascript"> | |
| $(document).ready(function(){ | |
| if (!window.jXHR){ | |
| var jxhr = document.createElement('script'); | |
| jxhr.type = 'text/javascript'; | |
| jxhr.src = '{{ root_url}}/javascripts/libs/jXHR.js'; | |
| var s = document.getElementsByTagName('script')[0]; | |
| s.parentNode.insertBefore(jxhr, s); | |
| } | |
| github.showRepos({ | |
| user: '{{site.github_user}}', | |
| count: {{site.github_repo_count}}, | |
| skip_forks: {{site.github_skip_forks}}, | |
| target: '#gh_repos' | |
| }); | |
| }); | |
| </script> | |
| <script src="{{ root_url }}/javascripts/github.js" type="text/javascript"> </script> | |
| </section> | |
| {% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var github = (function(){ | |
| function escapeHtml(str) { | |
| return $('<div/>').text(str).html(); | |
| } | |
| function render(target, repos){ | |
| var i = 0, fragment = '', t = $(target)[0]; | |
| for(i = 0; i < repos.length; i++) { | |
| fragment += '<li><a href="'+repos[i].html_url+'">'+repos[i].name+'</a><p>'+escapeHtml(repos[i].description||'')+'</p></li>'; | |
| } | |
| t.innerHTML = fragment; | |
| } | |
| return { | |
| showRepos: function(options){ | |
| $.ajax({ | |
| url: "https://api.github.com/users/"+options.user+"/repos?sort=pushed" // we don't need '&callback=?' because jQuery will add its own dynamic callback | |
| , dataType: 'jsonp' | |
| , error: function (err) { $(options.target + ' li.loading').addClass('error').text("Error loading feed"); } | |
| , success: function(data) { | |
| var repos = []; | |
| if (!data || !data.data) { return; } | |
| for (var i = 0; i < data.data.length; i++) { | |
| if (options.skip_forks && data.data[i].fork) { continue; } | |
| repos.push(data.data[i]); | |
| } | |
| if (options.count) { repos.splice(options.count); } | |
| render(options.target, repos); | |
| } | |
| }); | |
| } | |
| }; | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment