Hexo NexT 主题使用 utterances 搭建评论系统

在 Hexo NexT 中使用

在 Hexo NexT 中使用我的 NexT 版本是 5.1.4,不知道最新的版本有没有集成 utterances ,
如果有一般在主题配置文件中添加相关 utterances 配置即可。
但我使用 5.1.4 版本没有集成,需要修改NexT的布局文件,不然单添加配置不会在页面中看到效果的。

几个重要步骤:

编辑 Hexo 主题配置文件 _config.yml,添加以下配置

1
2
3
4
5
6
7
8
9
# 整合 utterances 评论
utterance:
enable: true
# 仓库名字,格式:[user-name]/[repo-name],如:lanweihong/utterance_repo
repo: xxx/yyy
# 主题
theme: github-light
# 映射配置
issue_term: pathname

在主题的 layout/_third-party/comments 目录中添加 utterance.swig文件:

1
2
3
4
5
{% if theme.utterance and theme.utterance.enable %}

<script type="text/javascript">!function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.setAttribute("issue-term","{{ theme.utterance.issue_term }}"),e.setAttribute("theme","{{ theme.utterance.theme }}"),e.setAttribute("repo","{{ theme.utterance.repo }}"),e.crossorigin="anonymous",e.src="https://utteranc.es/client.js",document.getElementById("utterance-container").appendChild(e)}()</script>

{% endif %}

编辑 layout/_third-party/comments/index.swig,添加以下配置加入 utterance.swig 文件:

1
{% include 'utterance.swig' %}

编辑 layout/_partials/comments.swig 文件,在最后加入以下内容,配置存放评论的 dom 元素:

1
2
3
4
{% elseif theme.utterance.enable %}
<div class="comments" id="comments">
<div id="utterance-container"></div>
</div>

参考: https://blog.lanweihong.com/posts/24011/

-------------本文结束感谢您的阅读-------------