Hexo pure主题配置utteranc评论

utteranc 官网
https://utteranc.es/

1 安装应用

https://github.com/apps/utterances
设置指定仓库

2 基本参数

官方的脚本如下:

1
2
3
4
5
6
7
<script src="https://utteranc.es/client.js"
repo="yansheng836/yansheng836.github.io"
issue-term="title"
theme="github-light"
crossorigin="anonymous"
async>
</script>

主要参数:

  • repo:存放评论的issues的仓库名(即步骤1指定访问的仓库),可以和博客相同,也可以不同。
  • issue-term:指定issues的标题,title表示使用文章的标题作为issues的标题。可选参数(只介绍部分):
  • URL:博客网址:网址全路径
  • pathname:URL 去掉域名
  • title:博客标题(推荐使用这个,因为上面两个涉及到网址,如果网址包含中文,会被转义,不方便看。)

3 pure 主题配置

修改 themes/pure/_config.yml

comment type 改为 utterance

添加 utterance 相关配置

修改 ejs
themes/pure/layout/_partial/post/comment.ejs 文件中插入以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<% } else if (theme.comment.type === 'utterance') { %>
<% if (theme.comment.utterance.enable){ %>
<section id="comments" class="comments">
<style>
.utterances{max-width: 100%;}
</style>
<script src="https://utteranc.es/client.js"
repo="<%= theme.comment.utterance.repo %>"
issue-term="<%= theme.comment.utterance.issue_term %>"
theme="<%= theme.comment.utterance.theme %>"
crossorigin="anonymous"
async>
</script>
</section>
<% } %>