Skip to main content

Module plugin

Module plugin 

Source
Expand description

Lifecycle hook plugin system.

§Plugin architecture for SSG

Provides a trait-based plugin system with lifecycle hooks for extending the static site generation pipeline.

§Lifecycle hooks

Plugins can hook into three stages of site generation:

  1. before_compile — Runs before compilation. Use for content preprocessing, metadata injection, or source transformation.
  2. after_compile — Runs after compilation. Use for HTML post-processing, asset optimization, or sitemap generation.
  3. on_serve — Runs before the dev server starts. Use for injecting dev-mode scripts or live-reload support.

§Example

use ssg::plugin::{Plugin, PluginContext};
use anyhow::Result;

#[derive(Debug)]
struct MinifyPlugin;

impl Plugin for MinifyPlugin {
    fn name(&self) -> &str { "minify" }

    fn after_compile(&self, ctx: &PluginContext) -> Result<()> {
        println!("Minifying files in {:?}", ctx.site_dir);
        // Walk site_dir and minify HTML/CSS/JS files
        Ok(())
    }
}

Structs§

PluginCache
Content-addressed cache that tracks file hashes so plugins can skip unchanged files across incremental builds.
PluginContext
Context passed to plugin hooks with paths and configuration.
PluginManager
Manages registered plugins and executes lifecycle hooks.

Traits§

Plugin
Trait for SSG plugins.