Skip to content

Commit

Permalink
docs: Sync documents for the config of plugin (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukiniro authored Nov 19, 2023
1 parent cbfea58 commit 39fe6b5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-grapes-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rspress/docs': patch
---

docs: Sync documents for the config of plugin
27 changes: 26 additions & 1 deletion packages/document/docs/en/plugin/system/plugin-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,43 @@ import { RspressPlugin } from '@rspress/shared';

export function pluginForDoc(): RspressPlugin {
return {
// Plugin name
name: 'plugin-name',
// Extend the config of the Rspress itself
config(config) {
return {
...config,
title: '新的文档标题',
title: 'New Document Title',
};
},
};
}
```

If it involves adding and removing a plugin, you need to implement it through `addPlugin` and `removePlugin`:

```tsx title="plugin.ts"
import { RspressPlugin } from '@rspress/shared';

export function pluginForDoc(): RspressPlugin {
return {
// Plugin name
name: 'plugin-name',
// Extend the config of Rspress itself
config(config, utils) {
// Add a plugin
utils.addPlugin({
name: 'plugin-name',
// ... other config of the plugin
});
// Remove a plugin, pass in the name of the plugin
utils.removePlugin('plugin-name');
return config;
},
};
}
```

### beforeBuild/afterBuild

- **Type**`(config: DocConfig, isProd: boolean) => void | Promise<void>`
Expand Down
13 changes: 6 additions & 7 deletions packages/document/docs/zh/plugin/system/plugin-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,30 @@ export function pluginForDoc(): RspressPlugin {
config(config) {
return {
...config,
// 这里可以扩展 Rspress 的配置
title: '新的文档标题',
};
},
};
}
```

If it involves adding and removing a plugin, you need to implement it through `addPlugin` and `removePlugin`:
如果涉及到添加和删除插件,需要通过 `addPlugin` `removePlugin` 来实现:

```tsx title="plugin.ts"
import { RspressPlugin } from '@rspress/shared';

export function pluginForDoc(): RspressPlugin {
return {
// Plugin name
// 插件名字
name: 'plugin-name',
// Extend the config of Rspress itself
// 扩展 Rspress 本身的配置
config(config, utils) {
// Add a plugin
// 添加插件
utils.addPlugin({
name: 'plugin-name',
// ... other config of the plugin
// ...插件的其他配置
});
// Remove a plugin, pass in the name of the plugin
// 通过插件名称来删除插件
utils.removePlugin('plugin-name');
return config;
},
Expand Down

0 comments on commit 39fe6b5

Please sign in to comment.