Hexo博客使用畅言评论插件

如何在Hexo博客上使用畅言评论插件?

Hexo默认提供[disqus, duoshuo, youyan]这三个评论插件,如果是要使用畅言的话,就要自己进行一些修改。

  1. 在主题的配置文件[_config.yml]中,加上以下语句,其中ID和KEY是你畅言后台中获取的。注意冒号后面的空格。

    1
    2
    3
    4
    5
    changyan:
    on: true
    id: 'cyszuTRxx'
    key: 'dd699ccdfb5bc856f8533e16906a3dxx'
    # 是否开启畅言评论,畅言服务在 Web 环境下运行,普通本地环境无法查看,请部署后在线上测试。
  2. 打开主题下面的[themes\xxxx\layout\/_partial\article.ejs],加上畅言的判断代码。

    1
    2
    3
    4
    5
    <% if (!index && post.comments){ %>
    <% if (theme.changyan.on) { %>
    <%- partial('comments/changyan') %>
    <% } %>
    <% } %>
  3. 在文件夹[themes\xxxx\layout\/_partial\comments\”]下,加上畅言的模板文件。文件名为[changyan.ejs]

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <!-- themes\xxxx\layout\_partial\comments\changyan.ejs -->
    <section id="comments">
    <div id="SOHUCS" sid="<%= post.id %>"></div>
    <script charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/changyan.js" ></script>
    <script type="text/javascript">
    window.changyan.api.config({
    appid: '<%= theme.changyan.id%>',
    conf: '<%= theme.changyan.key%>'
    });
    </script>
    </section>
文章目录
  1. 1. 如何在Hexo博客上使用畅言评论插件?
,