You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/plugins/plugin.md
+96-73
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,9 @@
3
3
slug: /development/plugins
4
4
---
5
5
6
-
# Overview
6
+
# Plugins Development Guide
7
+
8
+
Plugins are a way to extend the functionality of the Answer project. You can create your own plugins to meet your own needs.
7
9
8
10
:::tip
9
11
@@ -24,20 +26,32 @@ Currently we have three types of plugins:
24
26
25
27
We classify plugins into different types. Different types of plugins have different functions. Plugins of the same type have the same effect, but are implemented differently.
26
28
27
-
-**Connector**: The Connector plugin helps us to implement third-party login functionality.
28
-
-**Storage**: The Storage plugin helps us to upload files to third-party storage.
29
-
-**Cache**: Support for using different caching middleware.
30
-
-**Search**: Support for using search engines to speed up the search for question answers.
31
-
-**User Center**: Using the third-party user system to manage users.
32
-
-**Notification**: The Notification plugin helps us to send messages to third-party notification systems.
33
-
-**Route**: Provides support for custom routing.
34
-
-**Editor**: Supports extending the markdown editor's toolbar.
35
-
-**Reviewer**: Allows customizing the reviewer functionality.
36
-
-**Filter**: Filter out illegal questions or answers. (coming soon)
37
-
-**Render**: Parsers for different content formats. (coming soon)
29
+
Plugin Name | Template Type | Description
30
+
--- | --- | ---
31
+
Connector | Backend Plugin | The Connector plugin helps us to implement third-party login functionality
32
+
Storage | Backend Plugin | The Storage plugin helps us to upload files to third-party storage.
33
+
Cache | Backend Plugin | Support for using different caching middleware.
34
+
Search | Backend Plugin | Support for using search engines to speed up the search for question answers.
35
+
User Center | Backend Plugin | Using the third-party user system to manage users.
36
+
Notification | Backend Plugin | The Notification plugin helps us to send messages to third-party notification systems.
37
+
Route | Standard UI Plugin | Provides support for custom routing.
38
+
Editor | Standard UI Plugin | Supports extending the markdown editor's toolbar.
39
+
Captcha | Standard UI Plugin | Provides support for captcha.
40
+
Reviewer | Backend Plugin |Allows customizing the reviewer functionality.
41
+
Filter | Backend Plugin | Filter out illegal questions or answers. (coming soon)
42
+
Render | Standard UI Plugin | Parsers for different content formats. (coming soon)
38
43
39
44
## Create a Plugin
40
45
46
+
:::info
47
+
48
+
The **name** field in package.json is the name of the package we add dependencies to; do not use `_` to connect this field naming, please use `-`; for example:
49
+
50
+
"editor-chart" ✅
51
+
"editor_chart" ❌
52
+
53
+
:::
54
+
41
55
1. Go to the `ui > src > plugin` directory of the project.
42
56
43
57
2. Execute the following commands in that directory:
The plugin will be created in the `ui > src > plugin` directory.
52
65
53
-
## Debugging Plugins
54
66
55
-
### Debugging Backend Plugins
67
+
## Run the Plugin
68
+
69
+
### Run the Backend Plugin
56
70
57
71
1. First, execute `make ui` to compile the front-end code.
58
72
2. In the `cmd > answer > main.go` file, import your plugin.
@@ -82,7 +96,7 @@ The plugin will be created in the `ui > src > plugin` directory.
82
96
go run cmd/answer/main.go run -C ./answer-data
83
97
```
84
98
85
-
### DebuggingStandardUIPlugins
99
+
### Run the StandardUIPlugin
86
100
87
101
1. Go to the `ui` directory.
88
102
2. Install the dependencies.
@@ -97,7 +111,7 @@ The plugin will be created in the `ui > src > plugin` directory.
97
111
pnpm start
98
112
```
99
113
100
-
4. Refer to the [Debugging BackendPlugins](/docs/development/plugins#debugging-plugins) and add the plugin to the project.
114
+
4. Refer to the [Run the BackendPlugin](/docs/development/plugins#debugging-plugins) and add the plugin to the project.
101
115
102
116
## BackendPluginDevelopment
103
117
@@ -203,31 +217,82 @@ func init() {
203
217
}
204
218
```
205
219
206
-
### Debugging tips
220
+
##StandardUI plugin Development
207
221
208
-
:::tip
222
+
The default configuration is as follows:
209
223
210
-
During the development and debugging phase, you can use the following tips to avoid repetitive packaging.
224
+
```yaml
225
+
slug_name: <slug_name>
226
+
type: <type>
227
+
version: 0.0.1
228
+
author:
211
229
212
-
:::
230
+
```
231
+
```tsx
232
+
import i18nConfig from './i18n';
233
+
import Component from './Component';
234
+
import info from './info.yaml';
235
+
236
+
export default {
237
+
info: {
238
+
slug_name: info.slug_name,
239
+
type: info.type,
240
+
},
241
+
i18nConfig,
242
+
component: Component,
243
+
};
244
+
```
245
+
246
+
Among them, `type`、`slug_name` and `component` are required fields. `i18nConfig` and `hooks` are optional fields.
247
+
248
+
Currently the front end supports the following types of plugins:
249
+
* editor
250
+
* route
251
+
* captcha
252
+
253
+
### Editor plugin
254
+
255
+
Refer to [editor-chart](https://github.com/apache/incubator-answer-plugins/tree/main/editor-chart) for details.
213
256
214
-
1. Use answer source code for development.
215
-
2. Write your plugin directly in the plugin directory.
216
-
3. Import your plugin in the main function
257
+
### Route plugin
217
258
218
-
After that you just need to start the answer project normally and it will contain the plugins you developed.
259
+
The plugin configuration of the routing type adds the `route` field to the configuration file.
219
260
220
-
## Registration and activation of plugins
261
+
```yaml
262
+
slug_name: <slug_name>
263
+
route: /<route>
264
+
type: route
265
+
version: 0.0.1
266
+
author:
221
267
222
-
All types of plug-in activation registration (or display) logic are in the `ui/utils/pluginKit/index.ts` file. During the development process, you can modify `registerPlugins` or call `changePluginActiveStatus` either of these two methods. to control whether your plugin is displayed.
268
+
```
269
+
```tsx
270
+
import i18nConfig from './i18n';
271
+
import Component from './Component';
272
+
import info from './info.yaml';
273
+
274
+
export default {
275
+
info: {
276
+
slug_name: info.slug_name,
277
+
type: info.type,
278
+
route: info.route,
279
+
},
280
+
i18nConfig,
281
+
component: Component,
282
+
};
283
+
```
284
+
285
+
### Captcha plugin
223
286
224
-
## Builtin plugin
287
+
Refer to [captcha-basic](https://github.com/apache/incubator-answer-plugins/tree/main/captcha-basic) for details.
288
+
289
+
## Builtin plugin Development
225
290
226
291
It is not so different from React component, this plugin is more suitable for the following scenarios:
227
292
228
293
1. There are complex business logics that cannot be separated from the code (such as Oauth).
229
-
2. Some back-end plug-ins require UI support for business purposes (such as Search).
230
-
3. Thisplug-in has extremely low requirements for developers and requires no additional configuration work.
294
+
2. Some back-end plugins require UI support for business purposes (such as Search).
295
+
3. Thisplugin has extremely low requirements for developers and requires no additional configuration work.
231
296
232
297
### How to develop builtin plugin
233
298
@@ -267,46 +332,4 @@ It is not so different from React component, this plugin is more suitable for th
267
332
/>
268
333
```
269
334
270
-
4. **Publish plugin**: initiate the PR process normally and describe the plug-in function and scope of influence in detail.
271
-
272
-
## StandardUI plugin
273
-
274
-
This plugin is suitable for the following scenarios
275
-
276
-
1. A plug-in that can independently complete some UI functions and does not require back-end support;
277
-
2. The code needs to be isolated to prevent confusion with the main site;
In order to simplify the development and compilation process, we use [workspace](https://pnpm.io/next/workspaces) to manage this independent front-end warehouse.
282
-
283
-
### How to develop standard UI plugin
284
-
285
-
1. First, refer to the two existing warehouses above to familiarize yourself with the basic configuration and component export methods.
286
-
287
-
:::info
288
-
289
-
The **name** field in package.json is the name of the package we add dependencies to; do not use `_` to connect this field naming, please use `-`; for example:
290
-
291
-
"editor-chart" ✅
292
-
"editor_chart" ❌
293
-
294
-
:::
295
-
296
-
2. Go to the `ui/src/plugins` directory and create a directory, such as editor_chart, then add the components you want to develop, then modify the `ui/src/plugins/index.ts` file to export your components; **changes here during the release phase do not need to be submitted**.
297
-
298
-
```ts
299
-
export { default as editor_chart } from 'editor_chart';
300
-
```
301
-
302
-
3. Run`pnpm pre-install`, and re-run `pnpm start`, and finally call the changePluginActiveStatus method in PluginKit on the page where you need to load the plugin to activate the plugin. **Changes here during the release phase do not need to be submitted**.
303
-
304
-
```ts
305
-
import PluginKit from '@/utils/pluginKit';
306
-
// call this method
307
-
// @param1 plugin_name
308
-
// @param2 boolean; is whether or not to activate the
4. **Publish plugin**: after the function is developed, copy your entire plug-in folder to [incubator-answer-plugins](https://github.com/apache/incubator-answer-plugins), **and add `go.mod` `[plugin_name].go` `go.sum` these three files**; then initiate a PR and wait for review by relevant personnel; if incubator-answer If there are relevant changes in PR, please describe the scope of impact in PR.
335
+
4. **Publish plugin**: initiate the PR process normally and describe the plugin function and scope of influence in detail.
0 commit comments