项目作者: halo-dev

项目描述 :
💬 Halo comment component.
高级语言: Vue
项目地址: git://github.com/halo-dev/halo-comment-normal.git
创建时间: 2019-12-21T12:04:50Z
项目社区:https://github.com/halo-dev/halo-comment-normal

开源协议:

下载


halo-comment-normal

适用于 Halo 的评论组件。

⚠️ 当前仓库已不再维护,Halo 2.x 的官方评论模块可查阅:https://github.com/halo-sigs/plugin-comment-widget

npm

使用指南

  1. 进入后台 -> 系统 -> 博客设置 -> 评论设置

  2. 评论模块 JS 修改为:https://unpkg.com/halo-comment-normal@latest/dist/halo-comment.min.js

自定义配置

如果你需要自定义该评论组件,下面提供了一些属性:

属性 说明 默认值 可选
autoLoad 是否自动加载评论列表 true true false
showUserAgent 是否显示评论者的 UA 信息 true true false
loadingStyle 评论加载样式 default default circle balls

配置方法:

在引入评论组件的页面加上:

  1. <script>
  2. var configs = {
  3. autoLoad: true,
  4. showUserAgent: true
  5. }
  6. </script>

修改评论组件标签加上:

  1. :configs="configs"

示例:

  1. <halo-comment id="${post.id?c}" type="post" :configs="configs">
  1. <halo-comment id="${sheet.id?c}" type="sheet" :configs="configs">
  1. <halo-comment id="${journal.id?c}" type="journal" :configs="configs">

主题开发引用指南

方法一

新建 comment.ftl:

  1. <#macro comment target,type>
  2. <#if !post.disallowComment!false>
  3. <script src="//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
  4. <script src="${options.comment_internal_plugin_js!'//cdn.jsdelivr.net/npm/halo-comment-normal@1.1.1/dist/halo-comment.min.js'}"></script>
  5. <script>
  6. var configs = {
  7. autoLoad: true,
  8. showUserAgent: true
  9. }
  10. </script>
  11. <halo-comment id="${target.id?c}" type="${type}" :configs="configs"></halo-comment>
  12. </#if>
  13. </#macro>

然后在 post.ftl/sheet.ftl 中引用:

post.ftl:

  1. <#include "comment.ftl">
  2. <@comment target=post type="post" />

sheet.ftl:

  1. <#include "comment.ftl">
  2. <@comment target=sheet type="sheet" />

方法二

一般在主题制作过程中,我们可以将 head 部分抽出来作为宏模板,如:https://github.com/halo-dev/halo-theme-anatole/blob/master/module/macro.ftl,那么我们就可以将所需要的依赖放在 head 标签中:

  1. <head>
  2. ...
  3. <#if is_post?? && is_sheet??>
  4. <script src="//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
  5. <script src="${options.comment_internal_plugin_js!'//cdn.jsdelivr.net/npm/halo-comment-normal@1.1.1/dist/halo-comment.min.js'}"></script>
  6. <script>
  7. var configs = {
  8. autoLoad: true,
  9. showUserAgent: true
  10. }
  11. </script>
  12. </#if>
  13. ...
  14. </head>

然后在 post.ftl/sheet.ftl 中引用:

post.ftl:

  1. <#if !post.disallowComment!false>
  2. <halo-comment id="${post.id?c}" type="post" :configs="configs"></halo-comment>
  3. </#if>

sheet.ftl:

  1. <#if !sheet.disallowComment!false>
  2. <halo-comment id="${sheet.id?c}" type="sheet" :configs="configs"></halo-comment>
  3. </#if>

进阶:

可以将 configs 中的属性通过 settings.yaml 保存数据库中,以供用户自行选择,如:

settings.yaml:

  1. ...
  2. comment:
  3. label: 评论设置
  4. items:
  5. autoLoad:
  6. name: autoLoad
  7. label: 自动加载评论
  8. type: radio
  9. data-type: bool
  10. default: true
  11. options:
  12. - value: true
  13. label: 开启
  14. - value: false
  15. label: 关闭
  16. showUserAgent:
  17. name: showUserAgent
  18. label: 评论者 UA 信息
  19. type: radio
  20. data-type: bool
  21. default: true
  22. options:
  23. - value: true
  24. label: 显示
  25. - value: false
  26. label: 隐藏
  27. ...

那么我们需要将上面的 script 改为下面这种写法:

  1. <script>
  2. var configs = {
  3. autoLoad: ${settings.autoLoad!},
  4. showUserAgent: ${settings.showUserAgent!}
  5. }
  6. </script>

说明

  1. configs 可以不用配置。
  2. 具体主题开发文档请参考:https://halo.run/develop/theme/ready.html