forked from ilot/ilot-io
templates/page: drop comments
This commit is contained in:
parent
5099dd8cbd
commit
d6577e535a
1 changed files with 0 additions and 83 deletions
|
@ -132,89 +132,6 @@
|
|||
<TMPL_VAR TRAILS>
|
||||
</TMPL_IF>
|
||||
|
||||
<TMPL_UNLESS DYNAMIC>
|
||||
<!-- legacy Ikiwiki comments.pm section -->
|
||||
<TMPL_IF COMMENTS>
|
||||
<section id="comments">
|
||||
<TMPL_VAR COMMENTS>
|
||||
<TMPL_IF ADDCOMMENTURL>
|
||||
<div class="addcomment">
|
||||
<a href="<TMPL_VAR ADDCOMMENTURL>">Add a comment</a>
|
||||
</div>
|
||||
<TMPL_ELSE>
|
||||
<TMPL_UNLESS mastodon_host>
|
||||
<div class="addcomment">Comments on this page are closed.</div>
|
||||
</TMPL_UNLESS>
|
||||
</TMPL_IF>
|
||||
</section>
|
||||
</TMPL_IF>
|
||||
|
||||
<!-- Mastodon comments -->
|
||||
<TMPL_IF mastodon_host>
|
||||
<div class="mastodon-comments comments">
|
||||
<p>You can use your Mastodon account to reply to this <a class="link" href="https://<TMPL_VAR mastodon_host>/@<TMPL_VAR mastodon_username>/<TMPL_VAR mastodon_post>">post</a>.</p>
|
||||
<p id="mastodon-comments-list"><button id="load-comment">Load comments</button></p>
|
||||
<noscript><p>You need JavaScript to view the comments.</p></noscript>
|
||||
<script src="<TMPL_VAR BASEURL>assets/js/purify.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
function escapeHtml(unsafe) {
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
document.getElementById("load-comment").addEventListener("click", function() {
|
||||
document.getElementById("load-comment").innerHTML = "Loading...";
|
||||
fetch('https://<TMPL_VAR mastodon_host>/api/v1/statuses/<TMPL_VAR mastodon_post>/context')
|
||||
.then(function(response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if(data['descendants'] &&
|
||||
Array.isArray(data['descendants']) &&
|
||||
data['descendants'].length > 0) {
|
||||
document.getElementById('mastodon-comments-list').innerHTML = "";
|
||||
data['descendants'].forEach(function(reply) {
|
||||
reply.account.display_name = escapeHtml(reply.account.display_name);
|
||||
reply.account.emojis.forEach(emoji => {
|
||||
reply.account.display_name = reply.account.display_name.replace(`:${emoji.shortcode}:`,
|
||||
`<img src="${escapeHtml(emoji.static_url)}" alt="Emoji ${emoji.shortcode}" height="20" width="20" />`);
|
||||
});
|
||||
mastodonComment =
|
||||
`<div class="mastodon-comment comment">
|
||||
<div class="avatar">
|
||||
<img src="${escapeHtml(reply.account.avatar_static)}" height=60 width=60 alt="">
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="author">
|
||||
<a href="${reply.account.url}" rel="nofollow">
|
||||
<span>${reply.account.display_name}</span>
|
||||
<span class="disabled">${escapeHtml(reply.account.acct)}</span>
|
||||
</a>
|
||||
<a class="post" href="${reply.uri}" rel="nofollow">
|
||||
<time datetime="${reply.created_at}" pubdate="pubdate">
|
||||
${reply.created_at.replace(/(T\d+:\d+):\d+(\.\d+)?(.*)/, "$1$3")}
|
||||
</time>
|
||||
</a>
|
||||
</div>
|
||||
<div class="mastodon-comment-content">${reply.content}</div>
|
||||
</div>
|
||||
</div>`;
|
||||
document.getElementById('mastodon-comments-list').appendChild(DOMPurify.sanitize(mastodonComment, {'RETURN_DOM_FRAGMENT': true}));
|
||||
});
|
||||
} else {
|
||||
document.getElementById('mastodon-comments-list').innerHTML = "<p>Not comments found</p>";
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</TMPL_IF>
|
||||
|
||||
</TMPL_UNLESS>
|
||||
</div> <!-- /container -->
|
||||
|
||||
<footer class="footer" role="contentinfo">
|
||||
|
|
Loading…
Add table
Reference in a new issue