Hexo Fluid使用utterances评论系统,以及相关异常处理
今天在配置utterances的时候遇到了一些问题,在主题config里面设置都是无误的,但是评论仍然无法显示,通过F12检查之后发现是utterances没有授权(post 401)。
尽管已经在相关repo里安装了utterances,但是仍然显示401的错误,因此我采取了更加直接的方式去添加评论系统。
如何在Hexo Fluid上搭载utterances
1. 新建repo,设置utterances
在GitHub上面新建一个public的仓库,名称可以随意
进入 https://github.com/apps/utterances 为刚才新建的仓库安装utterances

之后在 https://utteranc.es/ 页面中对 utterances 进行设置

之后就是一些其它的参数,自行按照喜好设置即可:


最后我们得到:

1 |
|
2. 修改fluid主题设置
在 _config.yml 文件中修改相关设置
1 |
|
按照第一步最后得到的配置,继续在_config.yml中修改
1 |
|
至此,hexo clean && hexo g && hexo d 之后就可以成功搭载评论系统了
异常处理
1. Post 401
通过F12检查之后我们发现utterances的token请求异常是401,尽管成功在仓库安装了utterances,但是仍然出现了这种异常。

如果是这样的话,我们也可以在fluid主题的 ejs 文件中直接加入代码,在某些位置加入utterances评论系统,如打开 \themes\fluid\layout\post.ejs ,在每个post的末尾处加入评论系统:
原代码:
1 |
|
修改后:
1 |
|
之后再 hexo clean && hexo g && hexo d 之后也可以成功搭载评论系统
Summary
对 post 401 的处理方法其实就和在其他主题中加入 utterances 的方法差不多。
Hope that helps.
Hexo Fluid使用utterances评论系统,以及相关异常处理
https://zhenyumi.github.io/posts/4cba9f03/