Skip to content

Commit afda4f8

Browse files
authored
docs: add documentation for singlePage extension (#501)
Signed-off-by: Ryan Wang <i@ryanc.cc>
1 parent 04ee260 commit afda4f8

File tree

12 files changed

+250
-6
lines changed

12 files changed

+250
-6
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
```ts
2+
export interface ListedSinglePage {
3+
contributors: Array<{ // 页面的贡献者集合
4+
avatar: string; // 贡献者头像
5+
displayName: string; // 贡献者名称
6+
name: string; // 贡献者唯一标识
7+
}>;
8+
owner: { // 页面的作者信息
9+
avatar: string; // 作者头像
10+
displayName: string; // 作者名称
11+
name: string; // 作者唯一标识
12+
};
13+
page: { // 页面信息
14+
apiVersion: "content.halo.run/v1alpha1";
15+
kind: "SinglePage";
16+
metadata: {
17+
annotations: {};
18+
creationTimestamp: string;
19+
labels: {};
20+
name: string; // 页面的唯一标识
21+
version: number;
22+
};
23+
spec: {
24+
allowComment: boolean; // 是否允许评论
25+
baseSnapshot: string; // 内容基础快照
26+
cover: string; // 页面封面图
27+
deleted: boolean; // 是否已删除
28+
excerpt: { // 页面摘要
29+
autoGenerate: boolean; // 是否自动生成
30+
raw: string; // 摘要内容
31+
};
32+
headSnapshot: string; // 内容最新快照
33+
htmlMetas: Array<{}>;
34+
owner: string; // 页面作者的唯一标识
35+
pinned: boolean; // 是否置顶
36+
priority: number; // 页面优先级
37+
publish: boolean; // 是否发布
38+
publishTime: string; // 发布时间
39+
releaseSnapshot: string; // 已发布的内容快照
40+
slug: string; // 页面别名
41+
template: string; // 页面渲染模板
42+
title: string; // 页面标题
43+
visible: string; // 页面可见性
44+
};
45+
status: {
46+
commentsCount: number; // 页面评论总数
47+
conditions: Array<{
48+
lastTransitionTime: string;
49+
message: string;
50+
reason: string;
51+
status: string;
52+
type: string;
53+
}>;
54+
contributors: Array<string>;
55+
excerpt: string; // 最终的页面摘要,根据是否自动生成计算
56+
inProgress: boolean; // 是否有未发布的内容
57+
lastModifyTime: string; // 页面最后修改时间
58+
permalink: string; // 页面的永久链接
59+
phase: string;
60+
};
61+
};
62+
stats: {
63+
approvedComment: number; // 已审核的评论数
64+
totalComment: number; // 评论总数
65+
upvote: number; // 点赞数
66+
visit: number; // 访问数
67+
};
68+
}
69+
70+
```

docs/developer-guide/plugin/extension-points/ui/post-list-item-field-create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 文章数据列表显示字段
3-
description: 扩展文章数据列表显示字段 - plugin:list-item:field:create
3+
description: 扩展文章数据列表显示字段 - post:list-item:field:create
44
---
55

66
此扩展点用于扩展文章数据列表的显示字段。
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: 页面数据列表显示字段
3+
description: 扩展页面数据列表显示字段 - single-page:list-item:field:create
4+
---
5+
6+
此扩展点用于扩展页面数据列表的显示字段。
7+
8+
![页面数据列表显示字段](/img/developer-guide/plugin/extension-points/ui/single-page-list-item-field-create.png)
9+
10+
## 定义方式
11+
12+
```ts
13+
export default definePlugin({
14+
extensionPoints: {
15+
"single-page:list-item:field:create": (singlePage: Ref<ListedSinglePage>): EntityFieldItem[] | Promise<EntityFieldItem[]> => {
16+
return [
17+
{
18+
priority: 0,
19+
position: "start",
20+
component: markRaw(FooComponent),
21+
props: {},
22+
permissions: [],
23+
hidden: false,
24+
}
25+
];
26+
},
27+
},
28+
});
29+
```
30+
31+
```ts title="EntityFieldItem"
32+
export interface EntityFieldItem {
33+
priority: number;
34+
position: "start" | "end";
35+
component: Raw<Component>;
36+
props?: Record\<string, unknown\>;
37+
permissions?: string[];
38+
hidden?: boolean;
39+
}
40+
```
41+
42+
## 示例
43+
44+
此示例将添加一个显示页面 slug(别名)的字段。
45+
46+
```ts
47+
import { definePlugin } from "@halo-dev/console-shared";
48+
import { markRaw, type Ref } from "vue";
49+
import type { ListedSinglePage } from "@halo-dev/api-client";
50+
import { VEntityField } from "@halo-dev/components";
51+
52+
export default definePlugin({
53+
extensionPoints: {
54+
"single-page:list-item:field:create": (singlePage: Ref<ListedSinglePage>) => {
55+
return [
56+
{
57+
priority: 0,
58+
position: "end",
59+
component: markRaw(VEntityField),
60+
props: {
61+
description: singlePage.value.page.spec.slug,
62+
},
63+
permissions: [],
64+
hidden: false,
65+
},
66+
];
67+
},
68+
},
69+
});
70+
```
71+
72+
## 类型定义
73+
74+
### ListedSinglePage
75+
76+
```mdx-code-block
77+
import ListedSinglePage from "./interface/ListedSinglePage.md";
78+
79+
<ListedSinglePage />
80+
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: 页面数据列表操作菜单
3+
description: 扩展页面数据列表操作菜单 - single-page:list-item:operation:create
4+
---
5+
6+
此扩展点用于扩展页面数据列表的操作菜单项。
7+
8+
![页面数据列表操作菜单](/img/developer-guide/plugin/extension-points/ui/single-page-list-item-operation-create.png)
9+
10+
## 定义方式
11+
12+
```ts
13+
export default definePlugin({
14+
extensionPoints: {
15+
"single-page:list-item:operation:create": (
16+
singlePage: Ref<ListedSinglePage>
17+
): OperationItem<ListedSinglePage>[] | Promise<OperationItem<ListedSinglePage>[]> => {
18+
return [
19+
{
20+
priority: 10,
21+
component: markRaw(VDropdownItem),
22+
props: {},
23+
action: (item?: ListedSinglePage) => {
24+
// do something
25+
},
26+
label: "foo",
27+
hidden: false,
28+
permissions: [],
29+
children: [],
30+
},
31+
];
32+
},
33+
},
34+
});
35+
```
36+
37+
```mdx-code-block
38+
import OperationItem from "./interface/OperationItem.md";
39+
40+
<OperationItem />
41+
```
42+
43+
## 示例
44+
45+
此示例将实现一个操作菜单项,点击后会将页面内容作为文件下载到本地。
46+
47+
```ts
48+
import type { ListedSinglePage } from "@halo-dev/api-client";
49+
import { VDropdownItem } from "@halo-dev/components";
50+
import { definePlugin } from "@halo-dev/console-shared";
51+
import axios from "axios";
52+
import { markRaw } from "vue";
53+
54+
export default definePlugin({
55+
extensionPoints: {
56+
"single-page:list-item:operation:create": () => {
57+
return [
58+
{
59+
priority: 21,
60+
component: markRaw(VDropdownItem),
61+
label: "下载到本地",
62+
visible: true,
63+
permissions: [],
64+
action: async (singlePage: ListedSinglePage) => {
65+
const { data } = await axios.get(
66+
`/apis/api.console.halo.run/v1alpha1/single-pages/${singlePage.page.metadata.name}/head-content`
67+
);
68+
const blob = new Blob([data.raw], {
69+
type: "text/plain;charset=utf-8",
70+
});
71+
const url = window.URL.createObjectURL(blob);
72+
const link = document.createElement("a");
73+
link.href = url;
74+
link.download = `${singlePage.page.spec.title}.${data.rawType}`;
75+
link.click();
76+
},
77+
},
78+
];
79+
},
80+
},
81+
});
82+
```
83+
84+
## 类型定义
85+
86+
### ListedSinglePage
87+
88+
```mdx-code-block
89+
import ListedSinglePage from "./interface/ListedSinglePage.md";
90+
91+
<ListedSinglePage />
92+
```

sidebars.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ module.exports = {
287287
"developer-guide/plugin/extension-points/ui/plugin-installation-tabs-create",
288288
"developer-guide/plugin/extension-points/ui/theme-list-tabs-create",
289289
"developer-guide/plugin/extension-points/ui/post-list-item-operation-create",
290+
"developer-guide/plugin/extension-points/ui/single-page-list-item-operation-create",
290291
"developer-guide/plugin/extension-points/ui/comment-list-item-operation-create",
291292
"developer-guide/plugin/extension-points/ui/reply-list-item-operation-create",
292293
"developer-guide/plugin/extension-points/ui/plugin-list-item-operation-create",
@@ -295,6 +296,7 @@ module.exports = {
295296
"developer-guide/plugin/extension-points/ui/theme-list-item-operation-create",
296297
"developer-guide/plugin/extension-points/ui/plugin-list-item-field-create",
297298
"developer-guide/plugin/extension-points/ui/post-list-item-field-create",
299+
"developer-guide/plugin/extension-points/ui/single-page-list-item-field-create",
298300
"developer-guide/plugin/extension-points/ui/user-detail-tabs-create",
299301
"developer-guide/plugin/extension-points/ui/uc-user-profile-tabs-create",
300302
"developer-guide/plugin/extension-points/ui/dashboard-widgets",
62.1 KB
Loading
68.5 KB
Loading

versioned_docs/version-2.16/developer-guide/plugin/api-reference/ui/extension-points/post-list-item-field-create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 文章数据列表显示字段
3-
description: 扩展文章数据列表显示字段 - plugin:list-item:field:create
3+
description: 扩展文章数据列表显示字段 - post:list-item:field:create
44
---
55

66
此扩展点用于扩展文章数据列表的显示字段。

versioned_docs/version-2.17/developer-guide/plugin/api-reference/ui/extension-points/post-list-item-field-create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 文章数据列表显示字段
3-
description: 扩展文章数据列表显示字段 - plugin:list-item:field:create
3+
description: 扩展文章数据列表显示字段 - post:list-item:field:create
44
---
55

66
此扩展点用于扩展文章数据列表的显示字段。

versioned_docs/version-2.18/developer-guide/plugin/api-reference/ui/extension-points/post-list-item-field-create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 文章数据列表显示字段
3-
description: 扩展文章数据列表显示字段 - plugin:list-item:field:create
3+
description: 扩展文章数据列表显示字段 - post:list-item:field:create
44
---
55

66
此扩展点用于扩展文章数据列表的显示字段。

0 commit comments

Comments
 (0)