From 9c3f945957c0b051ca375d629f8e9548e5cdfb98 Mon Sep 17 00:00:00 2001 From: maple3142 Date: Fri, 3 Nov 2017 20:11:37 +0800 Subject: [PATCH] update firestore add count number on index page --- _config.yml | 1 + layout/_third-party/analytics/firestore.swig | 145 ++++++++++++------- 2 files changed, 96 insertions(+), 50 deletions(-) diff --git a/_config.yml b/_config.yml index 8ea31edd3..810f8fd28 100755 --- a/_config.yml +++ b/_config.yml @@ -531,6 +531,7 @@ firestore: collection: articles #required, a string collection name to access firestore database apiKey: #required projectId: #required + bluebird: false #enable this if you want to include bluebird 3.5.1(core version) Promise polyfill # Show PV/UV of the website/page with busuanzi. # Get more information on http://ibruce.info/2015/04/04/busuanzi/ diff --git a/layout/_third-party/analytics/firestore.swig b/layout/_third-party/analytics/firestore.swig index 3cd5f7c7f..7493c75f2 100644 --- a/layout/_third-party/analytics/firestore.swig +++ b/layout/_third-party/analytics/firestore.swig @@ -1,54 +1,99 @@ {% if theme.firestore.enable %} - - - + + {% if theme.firestore.bluebird %} + + {% endif %} + + 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) + }) + }) + } + })() + {% endif %}