Hexo-pure改造计划——添加utterances评论支持

温馨提示:点击页面下方以展开或折叠目录~

添加utterances评论支持。由于pure主题集成了几个评论系统,所以增加一个还算简单。

参考链接
Hexo NexT 使用 utterances 评论区
hexo-fluid添加utterances评论功能(详细图文过程)

新建utterances.ejs

themes\pure\layout\_script\_comment\目录新建utterances.ejs文件,文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
<% if (typeof(script) !== 'undefined' && script) { %>
<script src="https://utteranc.es/client.js"
repo=<%= theme.comment.utterances.repo %>
issue-term=<%= theme.comment.utterances.issue_term %>
label=<%= theme.comment.utterances.label %>
theme=<%= theme.comment.utterances.theme %>
crossorigin=<%= theme.comment.utterances.crossorigin %>
async>
</script>
<% } %>

更改comment.ejs文件

注意:comment.ejs文件有两个

一、更改themes\pure\layout\_script\comment.ejs代码

打开themes\pure\layout\_script\comment.ejs,在最后添加如下代码:

1
2
3
4
5
<% } else if (theme.comment.type === 'valine') { %>
<%- partial('_script/_comment/valine', { script: true }) %>
<% } else if (theme.comment.type === 'utterances') { %>
<%- partial('_script/_comment/utterances', { script: true }) %>
<% } %>

注意

1
2
3
<% } else if (theme.comment.type === 'valine') { %>
<%- partial('_script/_comment/valine', { script: true }) %>
<% } %>

这段代码是原来就有的,也可以插在这个文件其他合适的位置

二、更改themes\pure\layout\_partial\post\comment.ejs代码

打开themes\pure\layout\_partial\post\comment.ejs,插入如下代码

1
2
3
4
5
<% } else if (theme.comment.type === 'gitalk') { %>

<% } else if (theme.comment.type === 'utterances') { %>

<% } else if (theme.comment.type === 'valine') { %>

注意

1
2
3
<% } else if (theme.comment.type === 'gitalk') { %>

<% } else if (theme.comment.type === 'valine') { %>

这段代码是原来就有的,<% } else if (theme.comment.type === 'utterances') { %>,也可以插在其他合适位置

更改主题配置文件

打开themes\pure\_config.yml

找到comment,在对应位置加入:

1
2
3
4
5
6
7
8
9
comment:
type: utterances # 启用哪种评论系统
# 20230921 utterances
utterances:
repo: abobot/hexo-blog-comments
issue_term: pathname
label: 💬comments
theme: github-light
crossorigin: anonymous

其中的参数可以去https://utteranc.es/了解

完毕