# Hexo 搭建个人博客(四)

其实网站服务器已经搭建好,这篇博客是对前面的简单加深,这篇的目的是如何添加评论系统

因为 Hexo 没有自带的评论系统,所以需要第三方评论系统

本篇以免费无需登录的 Valine 为例

选择原因:Valine 免费,简洁,无需登录,集成好,方便

许多 Hexo 主题已经自带 Valine,不过需要获取 appid 和 appkey

# 1、注册登录 Leancloud

LeanCloud 是国内一家 BaaS 服务提供商,为移动应用开发提供稳定、可靠的后端云服务,业务范围既包括数据存储和云代码托管,也包括提供消息推送、应用统计等通用的移动开发组件,以及完善的技术支持和服务。

所有评论是放在 LeanCloud 数据库中的,所以如果想要删除评论等操作,需要在 LeanCloud 中操作

  • LeanCloud 网站:https://www.leancloud.cn/

  • 注册登录后需要实名认证,按照操作实名认证就 OK

# 2、创建应用

  • 单击创建应用,名称自己随便起,选择开发版就可

imgbed.cn图床

# 3、修改数据库

  • 创建完成后,打开应用(点击应用右上角的齿轮 设置)

imgbed.cn图床

  • 点击左边的存储,查看是否有 Comment 和 Counter

imgbed.cn图床

  • 如没有则创建,权限设为所有用户,点击左上角 “创建 Class”,设置如图,设置为无限制,点击创建
  • 注意:Class 名称必须是 CommentCounter ,不能是其他的名称

imgbed.cn图床

# 4、安全设置

  • 点击设置 → 安全中心,将除了数据存储的服务全部关闭,并绑定 web 安全域名,防止恶意调用。
  • 服务开关如图所示,只开启数据存储,Web 安全域名输入自己的域名。

imgbed.cn图床

# 5、获取应用 Keys

  • 进入应用 -> 设置 -> 应用 Keys
  • 获取 AppID 和 AppKey

imgbed.cn图床

# 6、配置 Hexo Valine

  • 打开本地博客目录,打开主题配置文件 _config.yml ,搜索 valine,填入 appId 和 appKey
valine:
  enable: true                          #这里改成 TRUE
  appId: xxxxxxxxxxxxxxxxxxxxxxxxxxx    #AppID 号填入这里
  appKey: xxxxxxxxxxxxxxxxxxxxxxxxxxx   #AppKey 号填入这里
  notify: false
  verify: false
  visitor: true
  avatar: 'mm' # Gravatar style : mm/identicon/monsterid/wavatar/retro/hide
  pageSize: 10
  placeholder: 'my name is lavender' # Comment Box placeholder
  background: /medias/comment_bg.png

# 7、重新部署 Hexo

  • 打开博客目录,地址栏输入 cmd ,输入
hexo clean 
hexo g -d

# 8、可能出现的问题

  1. 这是 5.1.3 版本 的配置文件
valine:
  enable: true
  appid: 
  appkey: 
  notify: false # mail notifier , https://github.com/xCss/Valine/wiki
  verify: false # Verification code
  placeholder: 'my name is lavender'
  1. 这是 6.0.1 版本 的配置文件
valine:
  enable: true
  app_id: 
  app_key: 
  notify: false # mail notifier , https://github.com/xCss/Valine/wiki
  verify: false # Verification code
  placeholder: 'my name is lavender'
  avatar: mm # gravatar style
  guest_info: nick,mail,link # custom comment header
  pageSize: 10 # pagination size
  1. 目前 Matery 主题的配置文件是这样
valine:
  enable: true              
  appId: 
  appKey: 
  notify: false
  verify: false
  visitor: true
  avatar: 'mm' # Gravatar style : mm/identicon/monsterid/wavatar/retro/hide
  pageSize: 10
  placeholder: 'my name is lavender' # Comment Box placeholder
  background: /medias/comment_bg.png
  • 注意到了吗?
  • appId 和 appKey 这两个字段名是不一样的,如果字段名不对,那么是不会去加载 Valine.min.js 文件,也就是评论系统根本不会生效,这是容易出现的问题
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Lavender 微信支付

微信支付

Lavender 支付宝

支付宝