0%

Hexo设置/使用LeanCloud配置Next主题文章浏览量的坑

刚开始搭建博客,决定给所有文章添加浏览量,并在首页显示
参考了很多教程,但还是遇到了坑,特此记录一下
主要解决了利用LeanCloud解决博客访问量显示不正常的问题

以下内容均转载自我的博客(欢迎访问,手动狗头
使用LeanCloud配置Next主题文章浏览量的坑

关于LeanCloud的配置

可以参考大佬的博客

为NexT主题添加文章阅读量统计功能

值得注意的是,Next最新版已经集成了LeanCloud的相关配置,故不需要对其他文件进行修改,仅需要修改主题配置文件_config.yml

关于_config.yml的配置

在这里遇到了一个坑

参考教程对_config.yml进行修改如下:

1
2
3
4
5
6
7
8
9
10
11
leancloud_visitors:
enable: true
app_id: xxx
app_key: xxx
# Required for apps from CN region
server_url:
# Dependencies: https://github.com/theme-next/hexo-leancloud-counter-security
# If you don't care about security in leancloud counter and just want to use it directly
# (without hexo-leancloud-counter-security plugin), set `security` to `false`.
security: false
betterPerformance: true

发现修改后首页显示阅读量如下(看上去挺正常,少得可怜):

Next主题LeanCloud配置错误首页

但是!

打开文章后发现,阅读次数直接不显示了

Next主题LeanCloud配置错误首页文章内容

经过一系列花里胡哨的操作(熬夜脱发)后

  • 改js
  • 重置LeanCloud应用
  • 改LeanCloud节点,换国际版

终于找到了答案

_config.yml配置文件中找到valine的配置,填入LeanCloud的appid与appkey,并更改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
valine:
enable: true
appid: xxx
appkey: xxx
notify: false # Mail notifier
verify: false # Verification code
placeholder: Just go go # Comment box placeholder
avatar: mm # Gravatar style
guest_info: nick,mail,link # Custom comment header
pageSize: 10 # Pagination size
language: # Language, available values: en, zh-cn
visitor: false # Article reading statistic
comment_count: true # If false, comment count will only be displayed in post page, not in home page
recordIP: false # Whether to record the commenter IP
serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in)
#post_meta_order: 0

最关键的地方在于设置 visitor: false

因为valine中的visitor与前面提到的leancloud_visitors配置冲突,故仅需要在这里设置为false即可


至此就完成了Next主题下文章浏览量的配置