count: count + 1 }) count++ } } } if (window.localStorage && increaseCount) { //mark as visited localStorage.setItem(title, true) } return count }) } function appendCountTo(el) { return function (count) { $(el).append( $('').addClass('post-visitors-count').append( $('').addClass('post-meta-divider').text('|') ).append( $('').addClass('post-meta-item-icon').append( $('').addClass('fa fa-users') ) ).append($('').text('阅读次数 ' + count)) ) } } var db = firebase.firestore() var articles = db.collection('articles') //https://hexo.io/docs/variables.html var isPost = ''.length > 0 var isArchive = '' === 'true' var isCategory = 'Java'.length > 0 var isTag = ''.length > 0 if (isPost) { //is article page var title = '' var doc = articles.doc(title) getCount(doc, true).then(appendCountTo($('.post-meta'))) } else if (!isArchive && !isCategory && !isTag) { //is index page var titles = [] //array to titles var postsstr = 'titles.push("java中Map、Collection接口常用实现类源码浅析");titles.push("Java 设计模式之桥接模式");titles.push("Java 设计模式之适配器模式");titles.push("Java 中使用Lambda表达式");titles.push("Spring Cloud配置SSH连接统一配置中心");' //if you have a better way to get titles of posts, please change it eval(postsstr) var promises = titles.map(function (title) { return articles.doc(title) }).map(function (doc) { return getCount(doc) }) Promise.all(promises).then(function (counts) { var metas = $('.post-meta') counts.forEach(function (val, idx) { appendCountTo(metas[idx])(val) }) }) } })()