Hexo-Next页脚增加统计功能

如果你使用的主题是NexT,那么你可以很方便的进行不蒜子的访客统计设置,仅仅只需要一步,打开主题的配置文件/theme/next/_config.yml,找到如下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Show PV/UV of the website/page with busuanzi.
# Get more information on http://ibruce.info/2015/04/04/busuanzi/
busuanzi_count:
# count values only if the other configs are false
enable: false
# custom uv span for the whole site
site_uv: true
site_uv_header: <i class="fa fa-user"></i>
site_uv_footer:
# custom pv span for the whole site
site_pv: true
site_pv_header: <i class="fa fa-eye"></i>
site_pv_footer:
# custom pv span for one page only
page_pv: true
page_pv_header: <i class="fa fa-file-o"></i>
page_pv_footer:

将enable的值由false改为true,便可以看到页脚出现访问量,上述配置表示:

  1. site_uv表示是否显示整个网站的UV数
  2. site_pv表示是否显示整个网站的PV数
  3. page_pv表示是否显示每个页面的PV数

下面是本人的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
busuanzi_count:
# count values only if the other configs are false
enable: true
# custom uv span for the whole site
site_uv: true
site_uv_header: 访客数
site_uv_footer: 人
# custom pv span for the whole site
site_pv: true
site_pv_header: 总访问量
site_pv_footer: 次
# custom pv span for one page only
page_pv: true
page_pv_header: <i class="fa fa-file-o"></i>
page_pv_footer: 阅读数

注意:当我们上面的配置都在正确的时候,运行:hexo s,我们会发现footer下面根本没有数字,打开控制台发现,原来报错404

原因分析:
由于定位到是不蒜子统计功能突然有问题了,所以前往不蒜子官网进行查看,发现官网有一段很重要的提示:“因七牛强制过期『dn-lbstatics.qbox.me』域名,与客服沟通无果,只能更换域名到『busuanzi.ibruce.info』!”所以定位到问题,原来是不蒜子使用的七牛的域名被强制过期。需要把 dn-lbstatics.qbox.me 域名更换为 busuanzi.ibruce.info

解决方案:
打开文件themes\next\layout_third-party\analytics\busuanzi-counter.swig:将域名dn-lbstatics.qbox.me改为busuanzi.ibruce.info即可。

最后,我们再运行:hexo s,footer出现了统计。不过在本地预览效果的时候,uv数和pv数会过大,这是由于不蒜子用户使用一个存储空间,所以使用localhost:4000进行本地预览的时候会导致数字异常,这是正常现象,只需要将博客部署至云端即可恢复正常。

-----------------------本文结束感谢您的阅读-----------------------
坚持原创技术分享,您的支持将鼓励我继续创作!
0%