-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<div class="gh-comments" data-comment-id="{{post.gh_issue_id}}" data-title="{{ post.title }}"></div> | ||
<script type="text/javascript"> | ||
(function (){ | ||
if (!'{{post.gh_issue_id}}') return false; | ||
var gh_comments = document.getElementsByClassName('gh-comments')[0]; | ||
var a = document.createElement('a'); | ||
a.href = '{{config.github_issues}}'; | ||
var gh_api = 'https://api.github.com/repos' + a.pathname; | ||
var gh_issue_id = '{{post.gh_issue_id}}'; | ||
var gh_issue_url = a.href + '/' + gh_issue_id; | ||
var gh_comments_url = gh_api + '/' + gh_issue_id + '/comments'; | ||
fetch(gh_comments_url, { | ||
headers: new Headers({ | ||
'Accept': 'application/vnd.github.v3.html+json', | ||
'Content-Type': 'application/json' | ||
}), | ||
method: 'GET' | ||
}).then((res) => { | ||
if (res.status == 200) return res.json(); | ||
let error = new Error('HTTP Exception[GET]'); | ||
error.status = res.status; | ||
error.statusText = res.statusText; | ||
error.url = res.url; | ||
throw error; | ||
}).then((json) => { | ||
gh_comments.insertAdjacentHTML('afterbegin', `<p>Visit the <a href="${gh_issue_url}">GitHub Issue</a> to comment on this post.</p>`); | ||
gh_comments.insertAdjacentHTML('afterbegin', `<h3>GitHub Comments</h3>`); | ||
for (let comment of json) { | ||
let date = new Date(comment.created_at); | ||
let c = '<div class="gh-comment">' + | ||
`<img src="${comment.user.avatar_url}" width="24px"> ` + | ||
`<a href="${comment.user.html_url}">${comment.user.login}</a>` + | ||
' posted at ' + | ||
`<time>${date.toUTCString()}</time>` + | ||
'<hr>' + | ||
comment.body_html + | ||
'</div>'; | ||
gh_comments.insertAdjacentHTML('beforeend', c); | ||
} | ||
}).catch((err) => { | ||
gh_comments.insertAdjacentHTML('afterbegin', `<p>Comments are not open for this post yet</p>`); | ||
gh_comments.insertAdjacentHTML('afterbegin', `<h3>GitHub Comments</h3>`); | ||
}) | ||
})(); | ||
</script> |
This file contains 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