$(document).ready(function() { // check if we show a blog post or not. Regex is defined in site-wide config var patt = new RegExp(BlogRegex); var isArticle = patt.test(RelPermalink); if (isArticle === false) { console.log("Not a blog post, no need to search for comments"); return; } $.ajax({ url: "/comments/getcomments.php", type: "get", data: { search : RelPermalink }, success: function(data) { var stats = data.stats; var root = data.stats.root; $("#like-count-container").append('
' + stats.favs + '
'); $("#reblog-count-container").append('
' + stats.reblogs + '
'); $("#reply-count-container").append('
' + stats.replies + '
'); var comments = data.comments; $.each(comments, function(key, value) { var timestamp = Date.parse(value.date); var date = new Date(timestamp); var comment = "
"; comment += ""; comment += "
" + value.author.display_name + " wrote at "; comment += "" + date.toDateString() + ', ' + date.toLocaleTimeString() + "
"; comment += "
" + value.toot + "
"; comment += "
"; var parentComment = document.getElementById(value.reply_to); if (value.reply_to === root || parentComment === null) { $("#comments").append(comment); } else { var selector = '#'+value.reply_to; $(selector).append(comment); } }); if (parseInt(root) > 0) { $("#reference").append("Join the discussion on Mastodon!"); } else { $("#comments").empty(); $("#statistics").empty(); $("#reference").append("Comments are handled by my Mastodon account. Sadly this article wasn't published at Mastodon. Feel free to send me a mail if you want to share your thoughts regarding this topic."); } } }); });