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
2 changed files
with
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{{ define "main" }} | ||
<main class="main"> | ||
{{ partial "breadcrumb.html" . }} | ||
<div class="single block"> | ||
<article class="entry"> | ||
{{- partial "entry/featured.html" (dict "page" . "IsSingle" true) }} | ||
{{- partial "entry/meta.html" (dict "page" . "class" "mb") }} | ||
<h1 class="entry__title">{{ .Title }}</h1> | ||
{{- partial "entry/toc.html" . }} | ||
<div class="entry__content">{{ .Content }}</div> | ||
{{ if or (.Param "share") (isset $.Params "tags") }} | ||
<footer class="entry__footer"> | ||
{{ partial "entry/tags.html" . }} | ||
{{ partial "entry/share.html" . }} | ||
</footer> | ||
{{ end }} | ||
</article> | ||
</div> | ||
</main> | ||
{{ partial "authorbox.html" . }} | ||
{{ partial "related.html" . }} | ||
<div id="comments"> | ||
{{ partial "comments.html" $ }} | ||
</div> | ||
{{ end }} |
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,65 @@ | ||
<script> | ||
var id = {{ .Params.GHissueID }}; | ||
|
||
if (id) | ||
{ | ||
let url = "https://github.com/morfikov/morfitronik-comments/issues/".concat(id); | ||
let api_url = "https://api.github.com/repos/morfikov/morfitronik-comments/issues/".concat(id, "/comments"); | ||
|
||
var commentsDiv = document.getElementById("comments"); | ||
|
||
let xhr = new XMLHttpRequest(); | ||
xhr.responseType = "json"; | ||
xhr.open("GET", api_url); | ||
xhr.setRequestHeader("Accept", "application/vnd.github.v3.html+json"); | ||
xhr.send(); | ||
|
||
xhr.onload = function() | ||
{ | ||
if (xhr.status != 200) | ||
{ | ||
let errorText = document.createElement("p"); | ||
errorText.innerHTML = "<i>Comments for this post yet are not opened yet (or you have GitHub scripts disabled).</i>"; | ||
commentsDiv.appendChild(errorText); | ||
} | ||
else | ||
{ | ||
let comments = xhr.response; | ||
|
||
let mainHeader = document.createElement("h2"); | ||
mainHeader.innerHTML = "Comments: ".concat(comments.length); | ||
commentsDiv.appendChild(mainHeader); | ||
|
||
let issueLink = document.createElement("p"); | ||
issueLink.innerHTML = "<i>You can leave a comment using this <a href='".concat(url, "'>GitHub issue</a>.</i>"); | ||
commentsDiv.appendChild(issueLink); | ||
|
||
comments.forEach(function(comment) | ||
{ | ||
let commentContent = document.createElement("div"); | ||
commentContent.setAttribute('class', 'gh-comment') | ||
commentContent.innerHTML = "".concat( | ||
"<div class='gh-header'>", | ||
"<img src='", comment.user.avatar_url, "' />", | ||
"<div style='margin:auto 0;'>", | ||
"<b><a class='gh-username' href='", comment.user.html_url, "'>", comment.user.login, "</a></b>", | ||
" commented at <em>", new Date(comment.created_at), "</em>", | ||
"</div>", | ||
"</div>", | ||
"<div class='gh-body'>", | ||
comment.body_html, | ||
"</div>" | ||
); | ||
commentsDiv.appendChild(commentContent); | ||
}); | ||
} | ||
}; | ||
|
||
xhr.onerror = function() | ||
{ | ||
let errorText = document.createElement("p"); | ||
errorText.innerHTML = "<i>Some error loading comments.</i>"; | ||
commentsDiv.appendChild(errorText); | ||
}; | ||
} | ||
</script> |