Contents
Create a Plugin
This guide describes how to create custom plugins for Uchū Docs.
Step 1: Implement the Base Interface
All plugins must implement the PluginInterface:
namespace Documentation\Plugins;
use Documentation\Interfaces\PluginInterface;
class MyPlugin implements PluginInterface {
public function getPriority(): int {
return 10; // Lower means higher priority
}
}
Step 2: Use Specific Interfaces
Depending on what your plugin needs to do, implement additional interfaces:
Modify Content
use Documentation\Interfaces\ContentModifierPluginInterface;
class MyPlugin implements PluginInterface, ContentModifierPluginInterface {
public function getPriority(): int {
return 10;
}
public function modifyContent(string $content, string $pageName): string {
return str_replace('foo', 'bar', $content);
}
}
Pre-Render Hook
use Documentation\Interfaces\PreRenderPluginInterface;
class MyPlugin implements PluginInterface, PreRenderPluginInterface {
public function getPriority(): int {
return 5;
}
public function preRender(string $pageName): void {
// Do something before rendering
}
}
Post-Render Hook
use Documentation\Interfaces\PostRenderPluginInterface;
class MyPlugin implements PluginInterface, PostRenderPluginInterface {
public function getPriority(): int {
return 5;
}
public function postRender(string $pageName, string $renderedContent): void {
// Log or modify after rendering
}
}
Plugin Diagram
_MERMAID_BLOCK68a0005fc969b565f4cf63a86559e9e1
Step 3: Register the Plugin
$pluginManager = new PluginManager();
$pluginManager->registerPlugin(new MyPlugin());
Best Practices
- Use
getPriority()to manage execution order. - Keep plugins focused and modular.
- Avoid long blocking operations in
preRender()orpostRender().