1. 前言之前说了 next 主题的优化和接入评论系统。让我们完成了自己所需的页面风格和排版,也可让访问用户在每篇博文评论,完成博主和访问用户的交互。 本章我们继续讲解其他重要功能。 既然是一个网站,那么我们就需要收集网站访问数据,提供流量趋势、来源分析、转化跟踪、页面热力图、访问流等多种统计分析服务;这时我们就需要引入——百度统计。 上述的统计只能在百度统计中查看,但我想在自己的网站页面直接就能看一些简单的数据。比如:网站访问人数,访问次数,每篇文章访问次数,网站总字数,每篇文章字数,阅读时长估算等。那么我们就可以引入不蒜子统计,字数统计,阅读次数统计了。具体那就参见下文了。 2. 百度统计 需要在百度统计进行注册,并拿到脚本的 ID。 ![]() 之后在主题配置文件中修改。 [root@iZ28xbsfvc4Z next]# pwd # 主题目录 /app/softinsall/hexo/themes/next [root@iZ28xbsfvc4Z next]# vim _config.yml # Baidu Analytics ID baidu_analytics: 983XXXXXXXXXXXXXXXXXXXXXXXXXX2 2.1. 访问报告查看 过半小时或一小时左右可在百度统计查看报告。 ![]() 3. 不蒜子统计 编辑主题配置文件中的 busuanzi_count 的配置项。 [root@iZ28xbsfvc4Z next]# pwd # 主题目录 /app/softinsall/hexo/themes/next [root@iZ28xbsfvc4Z next]# vim _config.yml # 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: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 # 每篇博文阅读次数,使用 leancloud 统计。原因是在「首页」中,leancloud 统计也能看阅读次数,而不蒜子则不行。 page_pv:false page_pv_header: 阅读次数 page_pv_footer: 次 3.1. 不蒜子域名修改 因七牛强制过期『dn-lbstatics.qbox.me』域名,与客服沟通无果,只能更换域名到『busuanzi.ibruce.info』! 修改如下: [root@iZ28xbsfvc4Z next]# pwd # 主题目录 /app/softinsall/hexo/themes/next [root@iZ28xbsfvc4Z next]# vim layout/_third-party/analytics/busuanzi-counter.swig {% if theme.busuanzi_count.enable %} <div class="busuanzi-count"> <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script> ……………… 3.2. 浏览器访问 页面底部 ![]() 4. 阅读次数统计 4.1. 在 LeanCloud 中创建 Class 在之前的评论系统中,已经讲解了LeanCloud 账号的创建、应用创建、获取App ID 和 App Key 已经安全加固。这里仅对阅读次数的 Class 创建做讲解。 数据栏中,_开头的都是系统预定义好的表。 为了区分,新建一张表来保存数据。为了保证对NexT主题的修改兼容,新建Class名字必须为Counter。 为了避免权限问题导致次数统计显示不正常,选择无限制,创建Class。 ![]() 4.2. 主题配置修改 在主题配置文件中修改: [root@iZ28xbsfvc4Z next]# pwd # 主题目录 /app/softinsall/hexo/themes/next [root@iZ28xbsfvc4Z next]# vim _config.yml # Show number of visitors to each article. # You can visit https://leancloud.cn get AppID and AppKey. leancloud_visitors: enable:true app_id: h7YmXXXXXXXXXXXXXX app_key: VhTGXXXXXXXXXX 4.3. 浏览器访问 文章标题 ![]() 5. 字数统计 用于统计文章的字数以及分析出阅读时间。 5.1. 安装 wordcount 插件 需要安装的插件 [root@iZ28xbsfvc4Z hexo]# pwd # 站点目录 /app/softinsall/hexo [root@iZ28xbsfvc4Z hexo]# npm install hexo-wordcount --save 5.2. 主题配置修改 在主题配置文件中修改。 [root@iZ28xbsfvc4Z next]# pwd # 主题目录 /app/softinsall/hexo/themes/next [root@iZ28xbsfvc4Z next]# vim _config.yml # Post wordcount display settings # Dependencies: https://github.com/willin/hexo-wordcount post_wordcount: item_text:true# 文本显示 wordcount:true# 单篇 字数统计 min2read:true# 单篇 阅读时长 totalcount:true# 网站 字数统计 # 该post_wordcount的所有设置另起一行显示 separated_meta:true [root@iZ28xbsfvc4Z next]# vim languages/zh-Hans.yml # 从英文改为中文 totalcount: 本站总字数 5.3. 浏览器访问 文章标题 ![]() 页面底部 ![]() 如果觉得不错就点个赞呗,毕竟我这么幽默,颜值又有担当 (-^O^-) ! ——————————END—————————— ![]() ---------------------------------------------------------------------------------------------------------------------- 我们尊重原创,也注重分享,文章来源于微信公众号:OpenInfo,建议关注公众号查看原文。如若侵权请联系qter@qter.org。 ---------------------------------------------------------------------------------------------------------------------- |