Created
April 21, 2014 12:01
-
-
Save ko2ic/11140768 to your computer and use it in GitHub Desktop.
OctopressのサイドバーにQiitaに投稿した人気記事を表示させる方法 ref: http://qiita.com/ko2ic/items/fafb61a67de0080c1178
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
qiita_user: user_name | |
qiita_display_count: 5 | |
default_asides:[custom/asides/qiita.html] |
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
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> |
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
{% if site.qiita_user %} | |
<section> | |
<h1>Qiita 人気の投稿</h1> | |
<ul id="qiita_post" class="post"> | |
</ul> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$.getJSON("https://qiita.com/api/v1/users/{{site.qiita_user}}/items",function(response){ | |
# 全投稿を取得して人気順に並び替える | |
response.sort(function(a, b){ | |
a = a.stock_count; | |
b = b.stock_count; | |
return b - a; | |
}); | |
for(var i = 0; i < response.length ; i++){ | |
var data = response[i]; | |
var aTag = $("<a/>").text(data.title).attr("href",data.url); | |
var iStockTag = $("<i/>").css({"color":"#000","margin-right":"1em"}).attr("class","fa fa-folder-o"); | |
iStockTag.append(" " + data.stock_count); | |
var iCommentTag = $("<i/>").css({"color":"#000"}).attr("class","fa fa-folder-o"); | |
iCommentTag.append(" " + data.comment_count); | |
var pTag = $("<p/>"); | |
pTag.append(iStockTag); | |
pTag.append(iCommentTag); | |
var liTag = $("<li/>").attr("class","post").attr("data-qiita-stock",data.stock_count).append(aTag).append(pTag); | |
$("#qiita_post").append(liTag); | |
# 指定した投稿数だけ表示する | |
if(i === {{site.qiita_display_count}} - 1){ | |
break; | |
} | |
} | |
}); | |
}); | |
</script> | |
</section> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment