Skip to content

Commit 2746f11

Browse files
authored
chore(plugin): Update plugin related documentation (apache#209)
1 parent fd5b3f3 commit 2746f11

File tree

3 files changed

+107
-76
lines changed

3 files changed

+107
-76
lines changed

Diff for: docs/development/overview.md renamed to docs/development/guide.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
22
slug: /development
33
---
4+
# Development Guide
45

5-
# Overview
6+
This guide will help you get started with the development of the project.
67

78
## Frontend
89

910
### Installation
1011

12+
1113
1. Ensure you have [node](https://nodejs.org/en) and [pnpm](https://pnpm.io/installation) installed.
1214
2. After cloning the repository, run the following command. This will install all dependencies as well as build all local packages.
1315

Diff for: docs/development/plugins/overview.md renamed to docs/development/plugins/plugin.md

+96-73
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
slug: /development/plugins
44
---
55

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.
79

810
:::tip
911

@@ -24,20 +26,32 @@ Currently we have three types of plugins:
2426

2527
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.
2628

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)
3843

3944
## Create a Plugin
4045

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+
4155
1. Go to the `ui > src > plugin` directory of the project.
4256

4357
2. Execute the following commands in that directory:
@@ -48,11 +62,11 @@ npx create-answer-plugin <pluginName>
4862

4963
3. Select the type of plugin you want to create.
5064

51-
The plugin will be created in the `ui > src > plugin` directory.
5265

53-
## Debugging Plugins
5466

55-
### Debugging Backend Plugins
67+
## Run the Plugin
68+
69+
### Run the Backend Plugin
5670

5771
1. First, execute `make ui` to compile the front-end code.
5872
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.
8296
go run cmd/answer/main.go run -C ./answer-data
8397
```
8498

85-
### Debugging Standard UI Plugins
99+
### Run the Standard UI Plugin
86100

87101
1. Go to the `ui` directory.
88102
2. Install the dependencies.
@@ -97,7 +111,7 @@ The plugin will be created in the `ui > src > plugin` directory.
97111
pnpm start
98112
```
99113

100-
4. Refer to the [Debugging Backend Plugins](/docs/development/plugins#debugging-plugins) and add the plugin to the project.
114+
4. Refer to the [Run the Backend Plugin](/docs/development/plugins#debugging-plugins) and add the plugin to the project.
101115

102116
## Backend Plugin Development
103117

@@ -203,31 +217,82 @@ func init() {
203217
}
204218
```
205219

206-
### Debugging tips
220+
## Standard UI plugin Development
207221

208-
:::tip
222+
The default configuration is as follows:
209223

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:
211229
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.
213256

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
217258

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.
219260

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:
221267
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
223286

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
225290

226291
It is not so different from React component, this plugin is more suitable for the following scenarios:
227292

228293
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. This plug-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. This plugin has extremely low requirements for developers and requires no additional configuration work.
231296

232297
### How to develop builtin plugin
233298

@@ -267,46 +332,4 @@ It is not so different from React component, this plugin is more suitable for th
267332
/>
268333
```
269334

270-
4. **Publish plugin**: initiate the PR process normally and describe the plug-in function and scope of influence in detail.
271-
272-
## Standard UI 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;
278-
279-
Existing examples:[editor-chart](https://github.com/apache/incubator-answer-plugins/tree/main/editor-chart), [editor-formula](https://github.com/apache/incubator-answer-plugins/tree/main/editor-formula).
280-
281-
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
309-
PluginKit.changePluginActiveStatus('editor_chart', true);
310-
```
311-
312-
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.

Diff for: sidebars.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,20 @@ module.exports = {
6666
type: 'category',
6767
label: 'Developer Guides',
6868
collapsed: true,
69+
link: {
70+
type: 'doc',
71+
id: 'development/guide',
72+
},
6973
items: [
70-
'development/overview',
7174
{
7275
type: 'category',
7376
label: 'Plugins',
7477
collapsed: true,
78+
link: {
79+
type: 'doc',
80+
id: 'development/plugins/plugin',
81+
},
7582
items: [
76-
'development/plugins/overview',
7783
'development/plugins/plugin-config',
7884
'development/plugins/plugin-translation',
7985
],

0 commit comments

Comments
 (0)