pub trait Plugin:
Debug
+ Send
+ Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn before_compile(&self, _ctx: &PluginContext) -> Result<()> { ... }
fn after_compile(&self, _ctx: &PluginContext) -> Result<()> { ... }
fn transform_html(
&self,
html: &str,
_path: &Path,
_ctx: &PluginContext,
) -> Result<String> { ... }
fn has_transform(&self) -> bool { ... }
fn on_serve(&self, _ctx: &PluginContext) -> Result<()> { ... }
}Expand description
Trait for SSG plugins.
Implement this trait to create a plugin that hooks into the site generation lifecycle. All hooks have default no-op implementations, so you only need to override the ones you care about.
§Stability contract
This trait is part of the SSG public API. The stability commitment
for the 1.0 line is:
- All current hook signatures are frozen. Once
1.0ships, no parameter, return type, or trait bound on an existing method will change without a major version bump. - New hooks land with a default
Ok(())implementation. Adding a new hook is therefore non-breaking — existingimpl Plugin for …blocks continue to compile. PluginContextis#[non_exhaustive]. New fields (e.g. additional caches, link graphs, image metadata) can be added without breaking downstream construction sites — those are constructed inside SSG, not by plugin authors.- Removing a hook requires a major bump. Hook removal is rare
and always preceded by a deprecation cycle of at least one
minor release with
#[deprecated]and a migration note in the CHANGELOG.
See API stability audit for the full Tier-A inventory.
Required Methods§
Provided Methods§
Sourcefn before_compile(&self, _ctx: &PluginContext) -> Result<()>
fn before_compile(&self, _ctx: &PluginContext) -> Result<()>
Called before site compilation begins.
Use this hook to preprocess content files, inject metadata, or validate source directories.
Sourcefn after_compile(&self, _ctx: &PluginContext) -> Result<()>
fn after_compile(&self, _ctx: &PluginContext) -> Result<()>
Called after site compilation completes.
Use this hook to post-process generated HTML, optimize assets, generate sitemaps, or perform any output transformation.
Sourcefn transform_html(
&self,
html: &str,
_path: &Path,
_ctx: &PluginContext,
) -> Result<String>
fn transform_html( &self, html: &str, _path: &Path, _ctx: &PluginContext, ) -> Result<String>
Per-file HTML transform hook — called once per HTML file during the fused transform pass.
Receives the current HTML content and returns the (possibly modified) HTML. The default implementation returns the input unchanged.
Plugins that implement this hook avoid redundant file I/O — the
pipeline reads each HTML file once, pipes it through all plugins’
transform_html hooks, then writes the result once.
Sourcefn has_transform(&self) -> bool
fn has_transform(&self) -> bool
Returns true if this plugin implements transform_html.
Override to true to opt in to the fused transform pass.
Sourcefn on_serve(&self, _ctx: &PluginContext) -> Result<()>
fn on_serve(&self, _ctx: &PluginContext) -> Result<()>
Called before the development server starts serving files.
Use this hook to inject dev-mode scripts, set up live-reload, or modify the serve directory.
Implementors§
impl Plugin for AccessibilityPlugin
impl Plugin for AiPlugin
impl Plugin for FingerprintPlugin
impl Plugin for ContentValidationPlugin
impl Plugin for CspPlugin
impl Plugin for ssg::deploy::DeployPlugin
impl Plugin for DraftPlugin
impl Plugin for HighlightPlugin
impl Plugin for I18nPlugin
impl Plugin for ImageOptimizationPlugin
image-optimization only.impl Plugin for IslandPlugin
impl Plugin for LiveReloadPlugin
impl Plugin for LlmPlugin
impl Plugin for MarkdownExtPlugin
impl Plugin for OgImagePlugin
impl Plugin for PaginationPlugin
impl Plugin for ssg::plugins::DeployPlugin
impl Plugin for ImageOptiPlugin
impl Plugin for MinifyPlugin
impl Plugin for AtomFeedPlugin
impl Plugin for HtmlFixPlugin
impl Plugin for ManifestFixPlugin
impl Plugin for NewsSitemapFixPlugin
impl Plugin for RssAggregatePlugin
impl Plugin for SitemapFixPlugin
impl Plugin for SbomPlugin
impl Plugin for LocalizedSearchPlugin
impl Plugin for SearchPlugin
impl Plugin for CanonicalPlugin
impl Plugin for JsonLdPlugin
impl Plugin for RobotsPlugin
impl Plugin for SeoPlugin
impl Plugin for ShortcodePlugin
impl Plugin for TaxonomyPlugin
impl Plugin for TemplatePlugin
templates only.