Skip to content

Commit 6ac195f

Browse files
committed
refactor: pv counter
当不蒜与评论系统(waline, twikoo, discuss, artalk)页面统计同时开启时,文章页的访问人数将由对应评论系统提供。
1 parent 6318b27 commit 6ac195f

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

_config.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ comments:
371371
server: https://yours-artalk-domain # 修改为自建的后端服务地址
372372
path: # 全局评论地址
373373
placeholder: # 评论占位
374+
visitor: true # 是否显示文章阅读数
374375
# artalk 有三类图片:1.上传至服务端 2.上传至服务端后利用upgit上传至图床 3.前端上传至图床(本配置为此类)
375376
# 配置此项时将覆盖服务端上传能力
376377
imageUploader:
@@ -491,6 +492,7 @@ comments:
491492
# 其他配置项按照yml格式继续填写即可 除了 [el path] 选项
492493
envId: xxxxxxxxxxxxxxx # 腾讯云环境id
493494
placeholder: #全局评论占位,也可以在管理面板中的配置管理处设置(此处优先级更高)
495+
visitor: true # 是否显示文章阅读数
494496

495497
# Waline
496498
# https://waline.js.org/
@@ -506,8 +508,8 @@ comments:
506508
api: # 图床地址
507509
token: # 图床验证
508510
resp: # 图片地址返回值的字段
509-
pageview: true # 浏览量统计
510-
comment: true # 评论数统计
511+
pageview: true # 是否显示文章阅读数
512+
comment: true # 是否显示文章评论数
511513
# 其他配置项按照yml格式继续填写即可 除了 [el path imageUploader] 选项
512514
# 组件属性地址:https://waline.js.org/reference/component.html
513515
# meta: ['nick', 'mail', 'link']
@@ -516,6 +518,7 @@ comments:
516518
# https://discuss.js.org
517519
discuss:
518520
serverURLs: # Discuss server address url
521+
visitStat: true # 是否显示文章阅读数
519522
# https://discuss.js.org/Quick-Start.html#path
520523

521524

layout/_meta/counter.ejs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
let checkComment = false;
1717
if (theme.plugins.busuanzi.enable
1818
|| (theme.comments.service=='waline' && theme.comments.waline.pageview)
19-
|| theme.comments.service=='twikoo'
20-
|| theme.comments.service=='discuss'
21-
|| theme.comments.service=='artalk') {
19+
|| (theme.comments.service=='twikoo' && theme.comments.twikoo.visitor)
20+
|| (theme.comments.service=='discuss' && theme.comments.discuss.visitStat)
21+
|| (theme.comments.service=='artalk' && theme.comments.artalk.visitor)) {
2222
checkComment = !checkComment;
2323
}
2424
%>
@@ -28,25 +28,27 @@
2828
<a class='notlink'>
2929
<p>
3030
<i class="<%- theme.article.body.meta_library.counter.icon %> fa-fw" aria-hidden="true"></i>
31-
<% if (theme.plugins.busuanzi.enable) { %>
32-
<span id="busuanzi_value_page_pv"><i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i></span>
33-
<% } else if (theme.comments.service=='waline' && theme.comments.waline.pageview) { %>
31+
<% if (theme.comments.service=='waline' && theme.comments.waline.pageview) { %>
3432
<span data-path="<%- url_for(path) %>" class="waline-pageview-count">
3533
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
3634
</span>
37-
<% } else if (theme.comments.service=='twikoo') { %>
35+
<% } else if (theme.comments.service=='twikoo' && theme.comments.twikoo.visitor) { %>
3836
<span id="twikoo_visitors">
3937
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
4038
</span>
41-
<% } else if (theme.comments.service=='discuss') { %>
39+
<% } else if (theme.comments.service=='discuss' && theme.comments.discuss.visitStat) { %>
4240
<span id="Discuss-Visitors">
4341
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
4442
</span>
45-
<% } else if (theme.comments.service=='artalk') { %>
43+
<% } else if (theme.comments.service=='artalk' && theme.comments.artalk.visitor) { %>
4644
<span id="artalk_visitors" data-page-key="<%- url_for(path) %>">
4745
<i class="fa-light fa-loader fa-spin fa-fw" aria-hidden="true"></i>
4846
</span>
49-
<% } %>
47+
<% } else if (theme.plugins.busuanzi.enable) { %>
48+
<span id="busuanzi_value_page_pv">
49+
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
50+
</span>
51+
<% } %>
5052
<span><%- theme.article.body.meta_library.counter.unit %></span>
5153
</p>
5254
</a>

layout/_meta/walinecount.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if (theme.comments.service == 'waline'){ %>
1+
<% if (theme.comments.service == 'waline' && theme.comments.waline.comment && page.comments !== false){ %>
22
<div class="new-meta-item comments-count">
33
<%
44
let commentPath;

0 commit comments

Comments
 (0)