Skip to content

Commit

Permalink
refactor: pv counter
Browse files Browse the repository at this point in the history
当不蒜与评论系统(waline, twikoo, discuss, artalk)页面统计同时开启时,文章页的访问人数将由对应评论系统提供。
  • Loading branch information
inkss committed Aug 19, 2022
1 parent 6318b27 commit 6ac195f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 5 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ comments:
server: https://yours-artalk-domain # 修改为自建的后端服务地址
path: # 全局评论地址
placeholder: # 评论占位
visitor: true # 是否显示文章阅读数
# artalk 有三类图片:1.上传至服务端 2.上传至服务端后利用upgit上传至图床 3.前端上传至图床(本配置为此类)
# 配置此项时将覆盖服务端上传能力
imageUploader:
Expand Down Expand Up @@ -491,6 +492,7 @@ comments:
# 其他配置项按照yml格式继续填写即可 除了 [el path] 选项
envId: xxxxxxxxxxxxxxx # 腾讯云环境id
placeholder: #全局评论占位,也可以在管理面板中的配置管理处设置(此处优先级更高)
visitor: true # 是否显示文章阅读数

# Waline
# https://waline.js.org/
Expand All @@ -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']
Expand All @@ -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


Expand Down
22 changes: 12 additions & 10 deletions layout/_meta/counter.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
%>
Expand All @@ -28,25 +28,27 @@
<a class='notlink'>
<p>
<i class="<%- theme.article.body.meta_library.counter.icon %> fa-fw" aria-hidden="true"></i>
<% if (theme.plugins.busuanzi.enable) { %>
<span id="busuanzi_value_page_pv"><i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i></span>
<% } else if (theme.comments.service=='waline' && theme.comments.waline.pageview) { %>
<% if (theme.comments.service=='waline' && theme.comments.waline.pageview) { %>
<span data-path="<%- url_for(path) %>" class="waline-pageview-count">
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
</span>
<% } else if (theme.comments.service=='twikoo') { %>
<% } else if (theme.comments.service=='twikoo' && theme.comments.twikoo.visitor) { %>
<span id="twikoo_visitors">
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
</span>
<% } else if (theme.comments.service=='discuss') { %>
<% } else if (theme.comments.service=='discuss' && theme.comments.discuss.visitStat) { %>
<span id="Discuss-Visitors">
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
</span>
<% } else if (theme.comments.service=='artalk') { %>
<% } else if (theme.comments.service=='artalk' && theme.comments.artalk.visitor) { %>
<span id="artalk_visitors" data-page-key="<%- url_for(path) %>">
<i class="fa-light fa-loader fa-spin fa-fw" aria-hidden="true"></i>
</span>
<% } %>
<% } else if (theme.plugins.busuanzi.enable) { %>
<span id="busuanzi_value_page_pv">
<i class="fa-solid fa-loader fa-spin fa-fw" aria-hidden="true"></i>
</span>
<% } %>
<span><%- theme.article.body.meta_library.counter.unit %></span>
</p>
</a>
Expand Down
2 changes: 1 addition & 1 deletion layout/_meta/walinecount.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if (theme.comments.service == 'waline'){ %>
<% if (theme.comments.service == 'waline' && theme.comments.waline.comment && page.comments !== false){ %>
<div class="new-meta-item comments-count">
<%
let commentPath;
Expand Down

0 comments on commit 6ac195f

Please sign in to comment.