客製化 NexT 主題:統計訪客人數與閱讀次數
添加網站訪客計數器
hexo主題可以搭配第三方計數器來統計訪客人數,這邊我選擇的是不蒜子,因為它有內建在next主題內所以設定起來很方便。
修改 hexo next 主題配置檔
首先打開theme/next/_config.yml,將enable改為true
# Show Views / Visitors of the website / page with busuanzi.
# Get more information on http://ibruce.info/2015/04/04/busuanzi
busuanzi_count:
enable: false
total_visitors: true
total_visitors_icon: fa fa-user
total_views: true
total_views_icon: fa fa-eye
post_views: true
post_views_icon: fa fa-eye
接著打開themes\next\layout\_third-party\analytics\busuanzi-counter.swig,確認src後面接的網址為不蒜子官方提供的最新網址。
{%- if theme.busuanzi_count.enable %}
<div class="busuanzi-count">
<script{{ pjax }} async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
{%- if theme.busuanzi_count.total_visitors %}
到這裡打開hexo server應該就能看到網站底下出現統計人數跟觀看數量的圖標與數字了,在local端會看到異常大的統計數字這是正常的,部署到github page後就會顯示正常。