halo icon indicating copy to clipboard operation
halo copied to clipboard

feat: add comment list APIs for theme-side

Open guqing opened this issue 3 years ago • 6 comments

What type of PR is this?

/kind feature /milestone 2.0 /area core /kind api-change

What this PR does / why we need it:

  • 新增主题端评论列表功能
  • 新增 <halo:comment /> html tag 用于扩展评论组件
  • 插件可以实现 CommentWidget 扩展点来渲染评论组件 html 块,以替换 <halo:comment /> 标签

Which issue(s) this PR fixes:

Fixes #2432

Special notes for your reviewer:

/cc @halo-dev/sig-halo

Does this PR introduce a user-facing change?

新增主题端评论列表功能

guqing avatar Sep 20 '22 08:09 guqing

/retitle feat: add comment list APIs for theme-side

ruibaby avatar Sep 20 '22 08:09 ruibaby

插件可以实现 CommentWidget 扩展点来渲染评论组件 html 块,以替换 <halo:comment /> 标签

@guqing 可以描述一下怎么在插件里面扩展 CommentWidget 这个拓展点吗?

ruibaby avatar Sep 20 '22 08:09 ruibaby

插件可以实现 CommentWidget 扩展点来渲染评论组件 html 块,以替换 <halo:comment /> 标签

@guqing 可以描述一下怎么在插件里面扩展 CommentWidget 这个拓展点吗?

首先插件实现扩展点 CommentWidget

class DefaultCommentWidget implements CommentWidget {
    void render(...) {
        // 实现里面的逻辑,见下文
    }
} 

一种是使用 IModelFactory 构造 html 结构,类似 VNode,使用场景适合动态值拼接

IModelFactory modelFactory = context.getModelFactory();
IModel model = modelFactory.createModel();
model.add(modelFactory.createText("文字Node"));
IOpenElementTag p = modelFactory.createOpenElementTag("p");
modelFactory.setAttribute(p, "class", "text-center");
model.add(p);
model.add(modelFactory.createText(HtmlUtils.htmlEscape("p 标签中的文字")));
model.add(modelFactory.createCloseElementTag("p"));
// render 后 modelFactory 就会解析为:文字Node<p class="text-center">p 标签中的文字</p>
structureHandler.replaceWith(model, false);

一种是直接使用字符串

String text = """
<p>hello world</p>
""";
structureHandler.replaceWith(text, false);

guqing avatar Sep 20 '22 08:09 guqing

@guqing 懂了(joke)

https://github.com/halo-sigs/plugin-comment-widget

PR Welcome 😃

ruibaby avatar Sep 20 '22 09:09 ruibaby

/hold until #2443 merged

guqing avatar Sep 21 '22 11:09 guqing

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JohnNiang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

f2c-ci-robot[bot] avatar Sep 26 '22 08:09 f2c-ci-robot[bot]

/unhold

JohnNiang avatar Sep 26 '22 08:09 JohnNiang