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
flowchart TD
A[Start: Create Plugin Class] --> B{Plugin Type}
B --> C[Content Modifier]
B --> D[Pre-Render]
B --> E[Post-Render]
B --> F[Other]
C --> G[Implement ContentModifierPluginInterface]
D --> H[Implement PreRenderPluginInterface]
E --> I[Implement PostRenderPluginInterface]
F --> J[Implement PluginInterface]
G --> K[Define modifyContent method]
H --> L[Define preRender method]
I --> M[Define postRender method]
J --> N[Custom Logic]
K --> O[Define getPriority method]
L --> O
M --> O
N --> O
O --> P[Instantiate PluginManager]
P --> Q[Call registerPlugin method]
Q --> R[Plugin Active]
R --> S[End]
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().