Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin:
    Debug
    + Send
    + Sync {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError> { ... }
    fn after_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError> { ... }
    fn transform_html(
        &self,
        html: &str,
        _path: &Path,
        _ctx: &PluginContext,
    ) -> Result<String, SsgError> { ... }
    fn has_transform(&self) -> bool { ... }
    fn needs_all_files(&self) -> bool { ... }
    fn on_serve(&self, _ctx: &PluginContext) -> Result<(), SsgError> { ... }
}
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:

  1. All current hook signatures are frozen. Once 1.0 ships, no parameter, return type, or trait bound on an existing method will change without a major version bump.
  2. New hooks land with a default Ok(()) implementation. Adding a new hook is therefore non-breaking — existing impl Plugin for … blocks continue to compile.
  3. PluginContext is #[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.
  4. 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§

Source

fn name(&self) -> &str

Returns the unique name of this plugin.

Provided Methods§

Source

fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>

Called before site compilation begins.

Use this hook to preprocess content files, inject metadata, or validate source directories.

Source

fn after_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>

Called after site compilation completes.

Use this hook to post-process generated HTML, optimize assets, generate sitemaps, or perform any output transformation.

Source

fn transform_html( &self, html: &str, _path: &Path, _ctx: &PluginContext, ) -> Result<String, SsgError>

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.

Source

fn has_transform(&self) -> bool

Returns true if this plugin implements transform_html. Override to true to opt in to the fused transform pass.

Source

fn needs_all_files(&self) -> bool

Returns true if this plugin must always observe the full cache.html_files() list — even during --incremental rebuilds that only invalidated a handful of pages.

SEO sitemap regeneration, SBOM emission, JSON-LD aggregation, and search-index builders all need the complete view of the site to produce correct output, so they opt in to true (the default). Plugins that genuinely work per-file (and so can be skipped for unaffected pages) override to false. (Issue #524 AC7.)

Source

fn on_serve(&self, _ctx: &PluginContext) -> Result<(), SsgError>

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Plugin for AccessibilityPlugin

Source§

impl Plugin for AgentApiPlugin

Source§

impl Plugin for AgenticDiscoveryPlugin

Source§

impl Plugin for AiPlugin

Source§

impl Plugin for AtomFeedPlugin

Source§

impl Plugin for AuditPlugin

Source§

impl Plugin for CanonicalPlugin

Source§

impl Plugin for ContentValidationPlugin

Source§

impl Plugin for CspPlugin

Source§

impl Plugin for ssg::deploy::DeployPlugin

Source§

impl Plugin for ssg::plugins::DeployPlugin

Source§

impl Plugin for DraftPlugin

Source§

impl Plugin for EdgeHeadersPlugin

Source§

impl Plugin for FingerprintPlugin

Source§

impl Plugin for HighlightPlugin

Source§

impl Plugin for HtmlFixPlugin

Source§

impl Plugin for I18nPlugin

Source§

impl Plugin for ImageOptiPlugin

Source§

impl Plugin for ImageOptimizationPlugin

Available on crate feature image-optimization only.
Source§

impl Plugin for IslandPlugin

Source§

impl Plugin for IsrManifestPlugin

Source§

impl Plugin for JsonFeedPlugin

Source§

impl Plugin for JsonLdPlugin

Source§

impl Plugin for LiveReloadPlugin

Source§

impl Plugin for LlmPlugin

Source§

impl Plugin for LocalizedSearchPlugin

Source§

impl Plugin for ManifestFixPlugin

Source§

impl Plugin for MarkdownExtPlugin

Source§

impl Plugin for MinifyPlugin

Source§

impl Plugin for NewsSitemapFixPlugin

Source§

impl Plugin for OembedPlugin

Source§

impl Plugin for OgImagePlugin

Source§

impl Plugin for PaginationPlugin

Source§

impl Plugin for RobotsPlugin

Source§

impl Plugin for RpcSchemaPlugin

Source§

impl Plugin for RssAggregatePlugin

Source§

impl Plugin for ssg::postprocess::SbomPlugin

Source§

impl Plugin for ssg::sbom::SbomPlugin

Source§

impl Plugin for SearchPlugin

Source§

impl Plugin for SeoPlugin

Source§

impl Plugin for ShortcodePlugin

Source§

impl Plugin for SitemapFixPlugin

Source§

impl Plugin for TaxonomyPlugin

Source§

impl Plugin for TemplatePlugin

Available on crate feature templates only.
Source§

impl Plugin for VectorSearchPlugin

Source§

impl Plugin for ViewTransitionsPlugin