halo
halo copied to clipboard
feat: add comment list APIs for theme-side
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?
新增主题端评论列表功能
/retitle feat: add comment list APIs for theme-side
插件可以实现 CommentWidget 扩展点来渲染评论组件 html 块,以替换 <halo:comment /> 标签
@guqing 可以描述一下怎么在插件里面扩展 CommentWidget 这个拓展点吗?
插件可以实现 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 懂了(joke)
https://github.com/halo-sigs/plugin-comment-widget
PR Welcome 😃
/hold until #2443 merged
[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
- ~~OWNERS~~ [JohnNiang]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
/unhold