Skip to content
Permalink
Browse files

Port github issues for comments integration

  • Loading branch information
bd808 committed Feb 25, 2017
1 parent d63bd45 commit 412c0b3fc45dacda2bd2800ca5b2d8a49d9ee46e
@@ -106,6 +106,10 @@
TWITTER_CARDS = True
TWITTER_USERNAME = 'bd808'

GITHUB_COMMENTS = True
GITHUB_USER = 'bd808'
GITHUB_REPO = 'bd808.github.com'

SITEMAP = {
'format': 'xml',
'priorities': {
@@ -109,4 +109,27 @@ <h1>
<!-- add shariff support -->
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/js/shariff.min.js"></script>
{% endif %}
{% if GITHUB_COMMENTS and article.github_issue_id %}
<script type="text/javascript">
$.ajax({
url: "https://api.github.com/repos/{{GITHUB_USER}}/{{GITHUB_REPO}}/issues/{{article.github_issue_id}}/comments"
, method: "get"
, headers: { Accept: "application/vnd.github.full+json" }
, error: function(e){}
, success: function(resp){
var cuser, cuserlink, clink, cbody, cavatarlink, cdate;
for (var i=0; i<resp.length; i++) {
cuser = resp[i].user.login;
cuserlink = "https://github.com/" + resp[i].user.login;
clink = "https://github.com/{{GITHUB_USER}}/{{GITHUB_REPO}}/issues/{{article.github_issue_id}}#issuecomment-" + resp[i].url.substring(resp[i].url.lastIndexOf("/")+1);
cbody = resp[i].body_html;
cavatarlink = resp[i].user.avatar_url;
cdate = (new Date(resp[i].created_at)).toLocaleString();

$("#comments").append('<div class="panel panel-default"><div class="panel-heading"><a class="comment-user" href="' + cuserlink + '"><img class="comment-gravatar" src="' + cavatarlink + '" alt="" width="20" height="20"> ' + cuser + '</a> commented <a class="comment-date" href="' + clink + '">' + cdate + '</a></div><div class="panel-body">' + cbody + '</div></div>');
}
}
});
</script>
{% endif %}
{% endblock %}
@@ -39,3 +39,14 @@ <h2>{{ _('Comments') }}</h2>

</section>
{% endif %}
{% if GITHUB_COMMENTS and article.github_issue_id %}
<section class="comments">
<header>
<h2>{{ _('Comments') }}</h2>
</header>
<div id="comments" class="panel-group"></div>
<footer>
<p>Visit <a href="https://github.com/{{GITHUB_USER}}/{{GITHUB_REPO}}/issues/{{article.github_issue_id}}">this post's issue page on GitHub</a> to add a comment.</p>
</footer>
</section>
{% endif %}

0 comments on commit 412c0b3

Please sign in to comment.
You can’t perform that action at this time.