Hexo集成DaoVoice实现网页在线通讯功能

什么是DaoVoice

即时在线通讯的一个工具,在网页上咨询问题,可以第一时间得到反馈。并且DaoVoice可以绑定微信,这样在网页上发送的消息,会第一时间推送到作者的微信上,非常方便。

注册DaoVoice

首先在DaoVoice官网注册一个账号

image-20230502234633827

获取appid

前往DaoVoice控制台,点击应用设置。

image-20230502234857918

选择安装到网站,获取appid

image-20230502235108143

配置Hexo

首先在themes/next/_config.yml文件末尾加上如下配置。

1
2
daovoice: true
daovoice_app_id: 你的appid

image-20230503000913834

然后在themes/next/_config.yml文件内搜索motion,如果enable为true的话,将它设置为false,不然集成了DaoVoice页面上会是一片空白,看不了文章。

image-20230503000829800

最后在themes/next/layout/_partials/head/head.swig文件末尾新增如下内容,注意:将appid替换成你自己的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{%- if theme.daovoice %}
<script>
(function(i, s, o, g, r, a, m) {
i["DaoVoiceObject"] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || [])
.push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
a.charset = "utf-8";
m.parentNode.insertBefore(a, m)
})(window, document, "script", ('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/你的appid.js", "daovoice")
daovoice('init', {
app_id: "{{theme.daovoice_app_id}}"
});
daovoice('update');
</script>
{%- endif %}

image-20230503000433067

效果

执行命令

1
hexo c && hexo g && hexo s

image-20230503001401062

自定义效果

免费版可自定义的东西不是很多,可以修改定制欢迎辞,聊天图标的颜色及位置,其他功能自行探索。

image-20230503002905412

参考文章

Hexo+DaoVoice实现网页在线通讯功能

Hexo使用Next主题时,添加DaoVoice后看不见文章的解决办法