Skip to content

Commit a1e3367

Browse files
authored
docs: refine readme (halo-dev#4)
1 parent b344f18 commit a1e3367

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

README.md

+51-41
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,66 @@
11
# plugin-comment-widget
22

3-
Halo 2.0 的评论模块插件,为前台提供完整的评论解决方案(WIP)
3+
Halo 2.0 的通用评论组件插件,为前台提供完整的评论解决方案
44

5-
## 说明
5+
## 开发环境
66

7-
使用 Vue 构建评论组件,最终产物(`comment-widget.iife.js` `style.css`)会被放置于 `src/main/resources/static`,插件需要配置 `ReverseProxy` 资源,如:
7+
```bash
8+
git clone [email protected]:halo-sigs/plugin-comment-widget.git
89

9-
```yaml
10-
apiVersion: plugin.halo.run/v1alpha1
11-
kind: ReverseProxy
12-
metadata:
13-
name: reverse-proxy-comment-widget
14-
rules:
15-
- path: /static/**
16-
file:
17-
directory: static
18-
```
10+
# 或者当你 fork 之后
1911

20-
最终可通过 `/assets/PluginCommentWidget/static/comment-widget.iife.js` 访问到评论组件的 JavaScript 资源。
12+
git clone [email protected]:{your_github_id}/plugin-comment-widget.git
13+
```
2114

22-
根据 [RFC](https://github.com/halo-dev/rfcs/tree/main/theme#%E4%B8%BB%E9%A2%98%E5%85%AC%E5%85%B1%E6%A8%A1%E6%9D%BF%E6%89%A9%E5%B1%95),最终主题使用该插件需要在对应扩展点插入以下代码:
15+
```bash
16+
cd path/to/plugin-comment-widget
17+
```
2318

24-
```html
25-
<div id="comment"></div>
26-
<script src="/assets/PluginCommentWidget/static/comment-widget.iife.js"></script>
27-
<script>
28-
CommentWidget.init(
29-
"#comment",
30-
"/assets/PluginCommentWidget/static/style.css",
31-
{
32-
group: "content.halo.run",
33-
version: "v1alpha1",
34-
kind: "Post",
35-
name: "<replace-post-name>",
36-
}
37-
);
38-
</script>
19+
```bash
20+
./gradlew build
3921
```
4022

41-
如果使用 Vue 构建 SPA 应用,也可以使用以下方式引入评论组件
23+
修改 Halo 配置文件
4224

43-
```bash
44-
pnpm install @halo-dev/comment-widget
25+
```yaml
26+
halo:
27+
plugin:
28+
runtime-mode: development
29+
classes-directories:
30+
- "build/classes"
31+
- "build/resources"
32+
lib-directories:
33+
- "libs"
34+
fixedPluginPath:
35+
- "/path/to/plugin-comment-widget"
4536
```
4637
47-
```vue
48-
<script lang="ts" setup>
49-
import { Comment } from "@halo-dev/comment-widget";
50-
import "@halo-dev/comment-widget/dist/style.css";
51-
</script>
38+
## 使用方式
39+
40+
1. 在 [Releases](https://github.com/halo-sigs/plugin-comment-widget/releases) 下载最新的 JAR 文件。
41+
2. 在 Halo 后台的插件管理上传 JAR 文件进行安装。
42+
43+
> 需要注意的是,此插件需要主题进行适配,不会主动在内容页加载评论组件。
44+
45+
## 主题适配
46+
47+
此插件是一个通用的评论组件插件,主题需要针对此类型插件做适配。Halo 为模板引擎提供了专门的标签(<halo:comment />),只需要在必要的位置添加此标签即可。
5248
53-
<template>
54-
<Comment postId="0"></Comment>
55-
</template>
49+
以下是代码示例:
50+
51+
```html
52+
<!-- /templates/post.html -->
53+
<halo:comment
54+
group="content.halo.run"
55+
kind="Post"
56+
th:attr="name=${post.metadata.name}"
57+
colorScheme="'light'"
58+
/>
5659
```
60+
61+
参数解释:
62+
63+
- `group`:自定义模型的 group,目前文章和自定义页面的分组均为 `content.halo.run`
64+
- `kind`:目前支持 Post(文章) 和 SinglePage(自定义页面) 两种类型,分别可用于 `post.html``page.html` 模板。
65+
- `name`:文章或者自定义页面的唯一标识,可通过 `post.metadata.name` 或者 `singlePage.metadata.name` 获取。
66+
- `colorScheme`:评论组件的颜色方案,支持 `light``dark` 两种,支持固定或者 JavaScript 变量。需要注意的是,如果需要固定一个值,那么需要添加单引号,如 `'dark'`。使用 JavaScript 变量时不需要。

0 commit comments

Comments
 (0)