💄 Update use waline pageview & add to homepage. Close #41, #42

This commit is contained in:
凡梦星尘 2022-10-29 18:15:39 +08:00
parent ac712b9277
commit 146bf52038
7 changed files with 51 additions and 4 deletions

View File

@ -0,0 +1,21 @@
/* Waline pageview plugin */
NexT.plugins.others.pageview = function() {
const busz = NexT.CONFIG.busuanzi;
if (busz != undefined && busz.pageview) return;
let pageview_js = undefined;
// Here can append others pageview plugin
const waline = NexT.CONFIG.waline;
if (waline != undefined && waline.cfg.pageview) {
pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.pageview.js);
}
if (pageview_js == undefined) return;
NexT.utils.getScript(pageview_js, function(){
Waline.pageviewCount({
serverURL: waline.cfg.serverurl
});
});
}

View File

@ -109,5 +109,12 @@ plugins:
name: mermaid
version: 9.1.7
file: dist/mermaid.min.js
# 文章访问统计
waline:
js:
name: '@waline/client'
version: 2.11.3
file: dist/pageview.js
alias: waline

View File

@ -7,6 +7,14 @@
"title" .Page.Title
-}}
{{/* Append waline pageview plugin */}}
{{ if and .Site.Params.waline .Site.Params.waline.pageView }}
{{ $pageview := dict
"js" .Site.Data.resources.plugins.waline.js
}}
{{ $pageCfg = merge $pageCfg (dict "pageview" $pageview) }}
{{ end }}
{{/* Append mermaid plugin */}}
{{ if .Params.mermaid }}
{{ $mermaid := dict

View File

@ -127,6 +127,11 @@
{{ $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

@ -27,6 +27,9 @@
{{ 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")) }}
{{ partial "post/header_meta/views.html" . }}
{{ end }}
</div>
{{- if not $.IsHome }}
<div class="post-meta-items">

View File

@ -2,9 +2,6 @@
{{- if .Site.Params.leancloudVisitors.enable }}
{{- $pageViewId = "leancloud-visitors-count" }}
{{- end }}
{{- if .Site.Params.waline.pageView }}
{{- $pageViewId = "waline-pageview-count" }}
{{- end }}
{{- if .Site.Params.analytics.busuanzi.postViews }}
{{- $pageViewId = "busuanzi_value_page_pv" }}
{{- end }}
@ -15,5 +12,7 @@
<span class="post-meta-item-text">
{{ print (T "PostViews") (T "SymbolColon") }}
</span>
<span id="{{ $pageViewId }}" data-path="{{ .RelPermalink | relLangURL }}"><i class="fa fa-sync fa-spin"></i></span>
<span {{ with $pageViewId }}id="{{ . }}"{{end}} {{ with .Site.Params.waline.pageView }}class="waline-pageview-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
<i class="fa fa-sync fa-spin"></i>
</span>
</span>

View File

@ -49,6 +49,10 @@
{{ if isset .Site.Params "waline" }}
{{ $walinejs := resources.Get "js/third-party/comments/waline.js" }}
{{ $nextjs = $nextjs | append $walinejs }}
{{ if .Site.Params.waline.pageView }}
{{ $pageviewjs := resources.Get "js/third-party/others/pageview.js" }}
{{ $nextjs = $nextjs | append $pageviewjs }}
{{ end }}
{{ end }}
{{ if isset .Site.Params "giscus" }}
{{ $giscusjs := resources.Get "js/third-party/comments/giscus.js" }}