functionqueryLeanCloud(k) { let root = this; let len = arguments.length; if (len == 1) { let notExist = new AV.Query("Comment"); notExist.doesNotExist('rid'); let isEmpty = new AV.Query("Comment"); isEmpty.equalTo('rid', ''); let q = AV.Query.or(notExist, isEmpty); if (k === '*') q.exists('url'); else q.equalTo('url', decodeURI(k)); q.addDescending('createdAt'); q.addDescending('insertedAt'); return q; } else { let ids = JSON.stringify(arguments[1]).replace(/(\[|\])/g, ''); let cql = `select * from ${root['config']['clazzName']} where rid in (${ids}) order by -createdAt,-createdAt`; return AV.Query.doCloudQuery(cql) } } var valine = new Valine({ el: '#valine_container_ba(因为主题已经有valine的这些参数了,这里随意填都行)', app_id: '换成自己的leancloud appid', app_key: '换成自己的', placeholder: '', serverURLs: '换成自己的api' });
//判断博主,heson改为自己的昵称 functionbozhu(e){ if (e == "heson"){ nick = e + '[博主]' return nick; } else { return e } }
//判断网址 functionwangzhi(e){ http = e.slice(0,4) https = e.slice(0,5) if (http == "http" || https == "https" ){ return e } elseif (e == "" || e == null || e == undefined){ return e } else { e = 'http://'+ e return e } }
//查询评论 valine.Q('*').limit(7).find().then(function (comments) { var hotComments = $("#hot-comments"); for (var i = 0; i < comments.length; i++) { if (i === 0) { console.log(comments[0]); } var nick = bozhu(comments[i]._serverData.nick); var content = comments[i]._serverData.comment; var newcontent = content.substring(0, 50).replace(/<[^>]+>/g,""); var url = comments[i]._serverData.url; var link = wangzhi(comments[i]._serverData.link); var updatedAt = timeago(comments[i].updatedAt); var commentId = '#' + comments[i].id; hotComments.append('<div class="card-comment-item"><div class="item-header-text"><a href="'+ link +'" target="_blank" rel="nofollow noopener noreferrer" class="newcomment" >' + nick + '</a> 发表于' + updatedAt + '</div><div class="item-text"><a href="' + url + commentId +'" rel="nofollow" style="color:#717171" class="comments-detail" >' + newcontent + '</a></div></div>'); } }); };