Skip to content

Instantly share code, notes, and snippets.

@alalwww
Created February 18, 2013 18:17
Show Gist options
  • Save alalwww/4979398 to your computer and use it in GitHub Desktop.
Save alalwww/4979398 to your computer and use it in GitHub Desktop.
https://github.com/dharFr/octo-about-me-from-twitter を自分用にカスタマイズ。 ロード前から site.description 削除してツイッターから取得してるよメッセージに変更。ツイッターから取得した location と description の文字サイズを小さくなるように変更。locationのあとにフォローボタンを追加。 スタイルをインライン指定してたり改行なしでHTMLつっこんでたりと超手抜き仕様。 作成したファイルは source/_includes/custom/asides/aboutmetwitter.html に配置して使う。
{% if site.twitter_user %}
<section>
<h1>About Me</h1>
<div id="twitter-profile" style="margin-top:0.5em;">
<p>
<strong>{{site.author}}</strong>
(<a href="http://twitter.com/{{site.twitter_user}}">@{{ site.twitter_user }}</a>)
</p>
<p>Getting profile from Twitter...</p>
</div>
<script type="text/javascript">
$.domReady(function(){
var container = $('#twitter-profile'),
user = "{{site.twitter_user}}";
function parseTwLinks(s) {
var twUrl = "http://www.twitter.com/"
s = s.replace(/ (@([\w]+))/g, function(match, p1, p2) {
return " <a href='"+twUrl+p2+"'>"+p1+"</a>"
}).replace(/ (#([\w]+))/g, function(match, p1, p2) {
return " <a href='"+twUrl+"#!/search?q=%23"+p2+"'>"+p1+"</a>"
})
return s
}
$.ajax({
url: "http://api.twitter.com/1/users/show.json?include_entities=false&screen_name="+user+"&callback=?"
, type: 'jsonp'
, error: function (err) { $('#twitter-profile').addClass('error'); }
, success: function(data) {
container.html('<img class="left" src="http://api.twitter.com/1/users/profile_image/'+user+'.json?size=bigger" alt="@'+user+'"><div><strong>'+data.name+'</strong> (<a href="http://twitter.com/'+user+'">@'+user+'</a>)</div><div style="font-size:80%">'+data.location+'</div><div><a href="http://twitter.com/{{ site.twitter_user }}" class="twitter-follow-button" data-show-count="{{ site.twitter_show_follower_count }}">Follow @{{ site.twitter_user }}</a></div><p style="clear:both;font-size:80%">'+parseTwLinks(data.description)+'</p>');
}
})
});
</script>
</section>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment