🎨 Improved page & comment counter, Close #74.

This commit is contained in:
elkan1788
2023-04-05 12:16:05 +08:00
parent c7e4f52499
commit fbac63d70e
9 changed files with 54 additions and 44 deletions

View File

@@ -7,6 +7,6 @@
{{ if isset .Site.Params.analytics "google" }}
{{ partial "_thirdparty/analytics/google.html" . }}
{{ end }}
{{ if isset .Site.Params.analytics "busuanzi" }}
{{ if or (isset .Site.Params.analytics "busuanzi") (eq .Site.Params.postMeta.views.plugin "busuanzi") }}
{{ partial "_thirdparty/analytics/busuanzi.html" . }}
{{ end }}

View File

@@ -8,7 +8,7 @@
}}
{{/* Append waline pageview & comment plugin */}}
{{ if and .Site.Params.waline ( or .Site.Params.waline.pageView .Site.Params.waline.comment) }}
{{ if or (eq .Site.Params.postMeta.views.plugin "waline") (eq .Site.Params.postMeta.comments.plugin "waline") }}
{{ $counter := dict
"js" .Site.Data.resources.plugins.waline.js
}}

View File

@@ -58,6 +58,16 @@
{{ $config = merge $config $localSearch }}
{{ end }}
{{ with .Site.Params.postMeta }}
{{ $postmeta := dict
"views" .views
"comments" .comments
}}
{{ $config = merge $config (dict "postmeta" $postmeta) }}
{{ else }}
{{ end }}
{{ if .Site.Params.algoliaSearch.enable }}
{{ $algoliaSearch := dict
"js" .Site.Data.resources.algolia
@@ -127,11 +137,6 @@
{{ $config = merge $config (dict "lawidget" $lawidget) }}
{{ end }}
{{ with .Site.Params.analytics.busuanzi }}
{{ $busz := dict "pageview" .postViews }}
{{ $config = merge $config (dict "busuanzi" $busz) }}
{{ end }}
{{ $globalVars.Set "config" $config }}
{{ with .Site.Params.customFilePath }}

View File

@@ -22,21 +22,19 @@
{{ end }}
{{ end }}
{{ if $.IsHome }} </h2> {{ else }} </h1> {{ end }}
{{ $isComment := and (.Scratch.Get "isComment") .Site.Params.waline.comment }}
{{ $comments := .Site.Params.postMeta.comments.enable }}
<div class="post-meta-container">
<div class="post-meta-items">
{{ partial "post/header_meta/created_date.html" . }}
{{ partial "post/header_meta/update_date.html" . }}
{{ partial "post/header_meta/categories.html" . }}
{{ if and $.IsHome (not (isset .Params "extlink")) }}
<div class="post-meta-items">
{{ if .Site.Params.waline.pageView }}
{{ if and .Site.Params.postMeta.views.enable (ne .Site.Params.postMeta.views.plugin "busuanzi") }}
{{ partial "post/header_meta/views.html" . }}
{{ end }}
{{ if $isComment }}
{{ if $comments }}
{{ partial "post/header_meta/comments.html" . }}
{{ end }}
</div>
{{ end }}
</div>
{{ if not $.IsHome }}
@@ -44,7 +42,7 @@
{{ partial "post/header_meta/words.html" . }}
{{ partial "post/header_meta/readtime.html" . }}
{{ partial "post/header_meta/views.html" . }}
{{ if $isComment }}
{{ if $comments }}
{{ partial "post/header_meta/comments.html" . }}
{{ end }}
</div>

View File

@@ -5,7 +5,7 @@
<span class="post-meta-item-text" title="{{ T "PostMeta.comments" }}">
{{ print (T "PostMeta.comments") (T "Symbol.colon") }}
</span>
<span {{ with .Site.Params.waline.comment }}class="waline-comment-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
<span {{ if and .Site.Params.postMeta.comments.enable (eq .Site.Params.postMeta.comments.plugin "waline") }}class="waline-comment-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
<i class="fa fa-sync fa-spin"></i>
</span>
</span>

View File

@@ -1,8 +1,8 @@
{{ if .Site.Params.postMeta.views.enable }}
{{ $pageViewId := "" }}
{{ if .Site.Params.leancloudVisitors.enable }}
{{ if eq .Site.Params.postMeta.views.plugin "leancloud" }}
{{ $pageViewId = "leancloud-visitors-count" }}
{{ end }}
{{ if .Site.Params.analytics.busuanzi.postViews }}
{{ else if eq .Site.Params.postMeta.views.plugin "busuanzi" }}
{{ $pageViewId = "busuanzi_value_page_pv" }}
{{ end }}
<span class="post-meta-item" title="{{ T "PostMeta.views" }}">
@@ -12,7 +12,8 @@
<span class="post-meta-item-text">
{{ print (T "PostMeta.views") (T "Symbol.colon") }}
</span>
<span {{ with $pageViewId }}id="{{ . }}"{{end}} {{ with .Site.Params.waline.pageView }}class="waline-pageview-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
<span {{ with $pageViewId }}id="{{ . }}"{{end}} {{ if eq .Site.Params.postMeta.views.plugin "waline" }}class="waline-pageview-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
<i class="fa fa-sync fa-spin"></i>
</span>
</span>
{{ end }}

View File

@@ -49,7 +49,7 @@
{{ if isset .Site.Params "waline" }}
{{ $walinejs := resources.Get "js/third-party/comments/waline.js" }}
{{ $nextjs = $nextjs | append $walinejs }}
{{ if or .Site.Params.waline.pageView .Site.Params.waline.comment }}
{{ if or .Site.Params.postMeta.views.enable .Site.Params.postMeta.comments.enable }}
{{ $counterjs := resources.Get "js/third-party/others/counter.js" }}
{{ $nextjs = $nextjs | append $counterjs }}
{{ end }}