mirror of
https://github.com/halo-dev/docs.git
synced 2026-01-14 07:02:53 +08:00
docs: update documentations for plugin development (#504)
```release-note None ```
This commit is contained in:
@@ -5,104 +5,9 @@ description: 这个例子展示了如何开发 Todo List 插件
|
||||
|
||||
本示例用于展示如何从插件模板创建一个插件并写一个 Todo List:
|
||||
|
||||
首先通过模板仓库创建一个插件,例如叫 `halo-plugin-todolist`
|
||||
首先参考 [入门 - 创建插件项目](../hello-world.md#创建插件项目) 文档创建一个新的插件项目并运行。
|
||||
|
||||
## 配置你的插件
|
||||
|
||||
1. 修改 `build.gradle` 中的 `group` 为你自己的,如:
|
||||
|
||||
```groovy
|
||||
group = 'run.halo.tutorial'
|
||||
```
|
||||
|
||||
2. 修改 `settings.gradle` 中的 `rootProject.name`
|
||||
|
||||
```groovy
|
||||
rootProject.name = 'halo-plugin-todolist'
|
||||
```
|
||||
|
||||
3. 修改插件的描述文件 `plugin.yaml`,它位于 `src/main/resources/plugin.yaml`。示例:
|
||||
|
||||
```yaml
|
||||
apiVersion: plugin.halo.run/v1alpha1
|
||||
kind: Plugin
|
||||
metadata:
|
||||
name: todolist
|
||||
spec:
|
||||
enabled: true
|
||||
requires: ">=2.0.0"
|
||||
author:
|
||||
name: halo-dev
|
||||
website: https://www.halo.run
|
||||
logo: https://www.halo.run/logo
|
||||
homepage: https://github.com/halo-dev/plugin-starter#readme
|
||||
repo: https://github.com/halo-dev/plugin-starter
|
||||
issues: https://github.com/halo-dev/plugin-starter/issues
|
||||
displayName: "插件 Todo List"
|
||||
description: "插件开发的 hello world,用于学习如何开发一个简单的 Halo 插件"
|
||||
license:
|
||||
- name: "GPL-3.0"
|
||||
url: "https://github.com/halo-dev/plugin-starter/blob/main/LICENSE"
|
||||
```
|
||||
|
||||
参考链接:
|
||||
|
||||
- [SemVer expression](https://github.com/zafarkhaja/jsemver#semver-expressions-api-ranges)
|
||||
- [表单定义](../../form-schema.md)
|
||||
|
||||
此时我们已经准备好了可以开发一个 TodoList 插件的一切,下面让我们正式进入 TodoList 插件开发教程。
|
||||
|
||||
## 运行插件
|
||||
|
||||
为了看到效果,首先我们需要让插件能最简单的运行起来。
|
||||
|
||||
1. 在 `src/main/java` 下创建包,如 `run.halo.tutorial`,在创建一个类 `TodoListPlugin`,它继承自 `BasePlugin` 类内容如下:
|
||||
|
||||
```java
|
||||
package run.halo.tutorial;
|
||||
|
||||
import run.halo.app.plugin.PluginContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.plugin.BasePlugin;
|
||||
|
||||
@Component
|
||||
public class TodoListPlugin extends BasePlugin {
|
||||
public TodoListPlugin(PluginContext pluginContext) {
|
||||
super(pluginContext);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`src/main/java` 下的文件结构如下:
|
||||
|
||||
```text
|
||||
.
|
||||
└── run
|
||||
└── halo
|
||||
└── tutorial
|
||||
└── TodoListPlugin.java
|
||||
```
|
||||
|
||||
2. 然后在项目目录执行命令
|
||||
|
||||
```shell
|
||||
./gradlew build
|
||||
```
|
||||
|
||||
3. 使用 `IntelliJ IDEA` 打开 Halo,参考 [Halo 开发环境运行](../../core/run.md) 及 [插件入门](../hello-world.md) 配置插件的运行模式和路径:
|
||||
|
||||
```yaml
|
||||
halo:
|
||||
plugin:
|
||||
runtime-mode: development
|
||||
fixed-plugin-path:
|
||||
# 配置为插件绝对路径
|
||||
- /Users/guqing/halo-plugin-todolist
|
||||
```
|
||||
|
||||
4. 启动 Halo,然后访问 `http://localhost:8090/console`
|
||||
|
||||
在插件列表将能看到插件已经被正确启用:
|
||||
如果能在插件列表中看到插件已经被正确启用,则说明插件已经运行成功。
|
||||
|
||||

|
||||
|
||||
|
||||
Reference in New Issue
Block a user