From ac712b9277f005e89c51eae2fa6465a7e196cd54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Thu, 27 Oct 2022 17:29:18 +0800 Subject: [PATCH] :zap: :bug: Fixed the 51la widget load data issue. --- .../components/third-party/search.scss | 24 ++++------- assets/js/next-boot.js | 2 +- assets/js/third-party/others/lawidget.js | 5 ++- assets/js/utils.js | 42 ++++++++++--------- .../_thirdparty/analytics/busuanzi.html | 8 +++- layouts/partials/init.html | 5 +++ layouts/partials/sidebar/siteinfo.html | 1 + 7 files changed, 46 insertions(+), 41 deletions(-) diff --git a/assets/css/_common/components/third-party/search.scss b/assets/css/_common/components/third-party/search.scss index 33d16fd..db7369b 100644 --- a/assets/css/_common/components/third-party/search.scss +++ b/assets/css/_common/components/third-party/search.scss @@ -24,13 +24,11 @@ .search-popup { background: var(--card-bg-color); border-radius: 5px; - height: 60%; + height: 65%; margin: auto; transform: scale(0); transition: transform .4s; width: 700px; - //display: flex; - //flex-wrap: wrap; .search-active & { transform: scale(1); @@ -77,10 +75,7 @@ } .search-result-container { - /* height: calc(100% - 65px); - @include mobile() { - height: calc(100% - 105px); - } */ + height: calc(100% - 55px); overflow: auto; padding: 0px 25px; } @@ -94,28 +89,23 @@ .search-meta-info { height: 26px; + display: flex; padding: 5px 0; .search-hit-stats { - font-size: $font-size-smaller; + font-size: $font-size-smaller; + width: 65%; padding: 2px 8px; - float: left; } .search-vendor { + width: 34%; text-align: right; font-size: $font-size-small; - @include mobile() { - font-size: $font-size-smaller; - } font-weight: bold; - float: right; img { width: 68px; - @include mobile() { - width: 48px; - } margin: 5px; vertical-align: middle; display: inline; @@ -220,4 +210,4 @@ margin: auto; } } -} +} \ No newline at end of file diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index 5ccb9cb..e34da36 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -49,7 +49,7 @@ NexT.boot.registerEvents = function() { NexT.boot.refresh = function() { - NexT.utils.calSiteInfo(); + NexT.utils.fmtSiteInfo(); if (!NexT.CONFIG.page.isPage) return; diff --git a/assets/js/third-party/others/lawidget.js b/assets/js/third-party/others/lawidget.js index 5e1598e..ff34674 100644 --- a/assets/js/third-party/others/lawidget.js +++ b/assets/js/third-party/others/lawidget.js @@ -10,7 +10,8 @@ NexT.plugins.others.lawidget = function() { crossorigin: 'anonymous', charset: 'UTF-8', defer: true - } - }); + }, + parentNode: document.getElementById('la-siteinfo-widget') + }, NexT.utils.fmtLaWidget()); }); } \ No newline at end of file diff --git a/assets/js/utils.js b/assets/js/utils.js index f9c66e1..9d5ab07 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -45,7 +45,7 @@ NexT.utils = { } }, - calSiteInfo: function () { + fmtSiteInfo: function () { const runtimeCount = document.getElementById('runTimes'); if (runtimeCount) { const publishDate = runtimeCount.getAttribute('data-publishDate'); @@ -86,29 +86,33 @@ NexT.utils = { const pushDateVal = this.diffDate(lastPushDate.getAttribute('data-lastPushDate'), 1); lastPushDate.innerText = pushDateVal; } + }, - const statisWidget = document.querySelectorAll('#la-siteinfo-widget span'); - if (statisWidget.length > 0) { - const valIds = [0, 2, 4, 6]; - const domIds = ['today_site_pv', 'yesterday_site_pv', 'month_site_pv', 'total_site_pv'] - for (var i in valIds) { - let pv = this.numberFormat(statisWidget[valIds[i]].innerText); - document.getElementById(domIds[i]).innerText = pv; + fmtLaWidget: function(){ + setTimeout(function(){ + const laWidget = document.querySelectorAll('#la-siteinfo-widget span'); + if (laWidget.length > 0) { + const valIds = [0, 2, 4, 6]; + const domIds = ['today_site_pv', 'yesterday_site_pv', 'month_site_pv', 'total_site_pv'] + for (var i in valIds) { + let pv = NexT.utils.numberFormat(laWidget[valIds[i]].innerText); + document.getElementById(domIds[i]).innerText = pv; + } } - } - - setTimeout(() => { this.fmtBusuanzi(); }, 500); + }, 800); }, fmtBusuanzi: function () { - const bszUV = document.getElementById('busuanzi_value_site_uv'); - if (bszUV) { - bszUV.innerText = this.numberFormat(bszUV.innerText); - } - const bszPV = document.getElementById('busuanzi_value_site_pv'); - if (bszPV) { - bszPV.innerText = this.numberFormat(bszPV.innerText); - } + setTimeout(function(){ + const bszUV = document.getElementById('busuanzi_value_site_uv'); + if (bszUV) { + bszUV.innerText = NexT.utils.numberFormat(bszUV.innerText); + } + const bszPV = document.getElementById('busuanzi_value_site_pv'); + if (bszPV) { + bszPV.innerText = NexT.utils.numberFormat(bszPV.innerText); + } + }, 800); }, numberFormat: function (number) { diff --git a/layouts/partials/_thirdparty/analytics/busuanzi.html b/layouts/partials/_thirdparty/analytics/busuanzi.html index c61ee65..0545dca 100644 --- a/layouts/partials/_thirdparty/analytics/busuanzi.html +++ b/layouts/partials/_thirdparty/analytics/busuanzi.html @@ -4,8 +4,12 @@ document.addEventListener('DOMContentLoaded', () => { script.charset = "UTF-8"; script.src = "{{ .Site.Data.resources.analytics.busuanzi }}"; - script.async = "true" - + script.async = false + script.defer = true + document.head.appendChild(script); + script.onload = function() { + NexT.utils.fmtBusuanzi(); + } }); diff --git a/layouts/partials/init.html b/layouts/partials/init.html index e286081..ffe97a0 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -114,6 +114,11 @@ {{ $config = merge $config (dict "addthis" $addthis) }} {{ end }} +{{ with .Site.Params.siteState.statistic }} +{{ $statis := dict "statis" . }} +{{ $config = merge $config $statis }} +{{ end }} + {{ with .Site.Params.analytics.laId }} {{ $lawidget := dict "js" $.Site.Data.resources.analytics.laWidget diff --git a/layouts/partials/sidebar/siteinfo.html b/layouts/partials/sidebar/siteinfo.html index 7024bdd..e03a5b9 100644 --- a/layouts/partials/sidebar/siteinfo.html +++ b/layouts/partials/sidebar/siteinfo.html @@ -26,6 +26,7 @@ {{- end }} {{- end }} {{- if eq .Site.Params.siteState.statistic.plugin "51la" }} +
{{ T "SiteInfoItems.todayViews" }}