2019-10-14 16:06:54 +02:00
$ ( document ) . ready ( function ( ) {
2019-10-16 20:03:39 +02:00
// 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 ) ;
2019-10-14 16:06:54 +02:00
if ( isArticle === false ) {
console . log ( "Not a blog post, no need to search for comments" ) ;
return ;
}
$ . ajax ( {
url : "/comments/getcomments.php" ,
type : "get" ,
data : {
2019-10-17 01:04:44 +02:00
search : RelPermalink
2019-10-14 16:06:54 +02:00
} ,
success : function ( data ) {
var stats = data . stats ;
var root = data . stats . root ;
$ ( "#like-count-container" ) . append ( '<div id="mastodon-like-count"><a href="' + stats . url + '"><span title="Likes"><i class="fa fa-star"></i>' + stats . favs + '</span></a></div></div>' ) ;
$ ( "#reblog-count-container" ) . append ( '<div id="mastodon-reblog-count"><a href="' + stats . url + '"><span title="Reblogs"><i class="fa fa-retweet"></i>' + stats . reblogs + '</span></a></div></div>' ) ;
$ ( "#reply-count-container" ) . append ( '<div id="mastodon-reply-count"><a href="' + stats . url + '"><span title="Comments"><i class="fa fa-comments"></i>' + stats . replies + '</span></a></div></div>' ) ;
var comments = data . comments ;
$ . each ( comments , function ( key , value ) {
var timestamp = Date . parse ( value . date ) ;
var date = new Date ( timestamp ) ;
var comment = "<div class='comment' id='" + key + "'>" ;
comment += "<img class='avatar' src='" + value . author . avatar + "' />" ;
comment += "<div class='author'><a class='displayName' href='" + value . author . url + "'>" + value . author . display _name + "</a> wrote at " ;
comment += "<a class='date' href='" + value . url + "'>" + date . toDateString ( ) + ', ' + date . toLocaleTimeString ( ) + "</a></div>" ;
comment += "<div class='toot'>" + value . toot + "</div>" ;
comment += "</div>" ;
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 ) {
2019-10-16 20:03:39 +02:00
$ ( "#reference" ) . append ( "<a href='" + MastodonUser + "/statuses/" + root + "'>Join the discussion on Mastodon!</a>" ) ;
2019-10-14 16:06:54 +02:00
} else {
$ ( "#comments" ) . empty ( ) ;
$ ( "#statistics" ) . empty ( ) ;
2019-10-17 01:29:00 +02:00
$ ( "#reference" ) . append ( "Comments are handled by my <a href='" + MastodonUser + "'>Mastodon account</a>. Sadly this article wasn't published at Mastodon. Feel free to <a href='" + CommentsContact + "'>send me a mail</a> if you want to share your thoughts regarding this topic." ) ;
2019-10-14 16:06:54 +02:00
}
}
} ) ;
} ) ;