From 6ac195f309843c86f22d5cecb6049216ef8f00e8 Mon Sep 17 00:00:00 2001 From: inkss Date: Fri, 19 Aug 2022 20:14:27 +0800 Subject: [PATCH] refactor: pv counter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当不蒜与评论系统(waline, twikoo, discuss, artalk)页面统计同时开启时,文章页的访问人数将由对应评论系统提供。 --- _config.yml | 7 +++++-- layout/_meta/counter.ejs | 22 ++++++++++++---------- layout/_meta/walinecount.ejs | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/_config.yml b/_config.yml index 0f8115c54..3302c4af2 100755 --- a/_config.yml +++ b/_config.yml @@ -371,6 +371,7 @@ comments: server: https://yours-artalk-domain # 修改为自建的后端服务地址 path: # 全局评论地址 placeholder: # 评论占位 + visitor: true # 是否显示文章阅读数 # artalk 有三类图片:1.上传至服务端 2.上传至服务端后利用upgit上传至图床 3.前端上传至图床(本配置为此类) # 配置此项时将覆盖服务端上传能力 imageUploader: @@ -491,6 +492,7 @@ comments: # 其他配置项按照yml格式继续填写即可 除了 [el path] 选项 envId: xxxxxxxxxxxxxxx # 腾讯云环境id placeholder: #全局评论占位,也可以在管理面板中的配置管理处设置(此处优先级更高) + visitor: true # 是否显示文章阅读数 # Waline # https://waline.js.org/ @@ -506,8 +508,8 @@ comments: api: # 图床地址 token: # 图床验证 resp: # 图片地址返回值的字段 - pageview: true # 浏览量统计 - comment: true # 评论数统计 + pageview: true # 是否显示文章阅读数 + comment: true # 是否显示文章评论数 # 其他配置项按照yml格式继续填写即可 除了 [el path imageUploader] 选项 # 组件属性地址:https://waline.js.org/reference/component.html # meta: ['nick', 'mail', 'link'] @@ -516,6 +518,7 @@ comments: # https://discuss.js.org discuss: serverURLs: # Discuss server address url + visitStat: true # 是否显示文章阅读数 # https://discuss.js.org/Quick-Start.html#path diff --git a/layout/_meta/counter.ejs b/layout/_meta/counter.ejs index b5a8cfa0a..29e93923d 100644 --- a/layout/_meta/counter.ejs +++ b/layout/_meta/counter.ejs @@ -16,9 +16,9 @@ let checkComment = false; if (theme.plugins.busuanzi.enable || (theme.comments.service=='waline' && theme.comments.waline.pageview) - || theme.comments.service=='twikoo' - || theme.comments.service=='discuss' - || theme.comments.service=='artalk') { + || (theme.comments.service=='twikoo' && theme.comments.twikoo.visitor) + || (theme.comments.service=='discuss' && theme.comments.discuss.visitStat) + || (theme.comments.service=='artalk' && theme.comments.artalk.visitor)) { checkComment = !checkComment; } %> @@ -28,25 +28,27 @@

- <% if (theme.plugins.busuanzi.enable) { %> - - <% } else if (theme.comments.service=='waline' && theme.comments.waline.pageview) { %> + <% if (theme.comments.service=='waline' && theme.comments.waline.pageview) { %> - <% } else if (theme.comments.service=='twikoo') { %> + <% } else if (theme.comments.service=='twikoo' && theme.comments.twikoo.visitor) { %> - <% } else if (theme.comments.service=='discuss') { %> + <% } else if (theme.comments.service=='discuss' && theme.comments.discuss.visitStat) { %> - <% } else if (theme.comments.service=='artalk') { %> + <% } else if (theme.comments.service=='artalk' && theme.comments.artalk.visitor) { %> - <% } %> + <% } else if (theme.plugins.busuanzi.enable) { %> + + + + <% } %> <%- theme.article.body.meta_library.counter.unit %>

diff --git a/layout/_meta/walinecount.ejs b/layout/_meta/walinecount.ejs index 2220812b1..ea9482638 100644 --- a/layout/_meta/walinecount.ejs +++ b/layout/_meta/walinecount.ejs @@ -1,4 +1,4 @@ -<% if (theme.comments.service == 'waline'){ %> +<% if (theme.comments.service == 'waline' && theme.comments.waline.comment && page.comments !== false){ %>
<% let commentPath;