pub struct ImageOptimizationPlugin {
pub quality: u8,
pub avif_quality: u8,
pub lazy_avif: bool,
pub breakpoints: Vec<u32>,
}Expand description
Plugin that optimises images and rewrites HTML with <picture> tags.
Runs in after_compile:
- Scans
site_dirfor JPEG/PNG images - Generates WebP and AVIF variants at responsive widths
- Rewrites
<img>tags to<picture>withsrcset - Adds
loading="lazy",decoding="async",width,height
The quality and breakpoints are configurable via the struct fields.
Fields§
§quality: u8WebP encoding quality (1–100). Defaults to 80.
avif_quality: u8AVIF encoding quality (1–100). Defaults to 70 — see the
DEFAULT_AVIF_QUALITY private constant for the rationale.
lazy_avif: boolSkip AVIF encoding for non-priority images (saves build time
at the cost of bandwidth on modern browsers). Hero images
marked fetchpriority="high" always get AVIF regardless —
see issue #521 AC5.
Currently exposed as a config knob; per-image priority data is
only known to the HTML rewriter (which preserves
fetchpriority="high" and loading="eager"), so the present
implementation always encodes AVIF for every responsive variant
of every collected image. Honoured-by-default in a follow-up
once priority metadata is plumbed from the shortcode layer
into collect_images.
breakpoints: Vec<u32>Responsive width breakpoints in pixels. Defaults to [320, 640, 1024, 1440].
Trait Implementations§
Source§impl Clone for ImageOptimizationPlugin
impl Clone for ImageOptimizationPlugin
Source§fn clone(&self) -> ImageOptimizationPlugin
fn clone(&self) -> ImageOptimizationPlugin
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageOptimizationPlugin
impl Debug for ImageOptimizationPlugin
Source§impl Default for ImageOptimizationPlugin
Available on crate feature image-optimization only.
impl Default for ImageOptimizationPlugin
image-optimization only.Source§impl Plugin for ImageOptimizationPlugin
Available on crate feature image-optimization only.
impl Plugin for ImageOptimizationPlugin
image-optimization only.Source§fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
Source§fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>
fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>
Source§fn transform_html(
&self,
html: &str,
_path: &Path,
_ctx: &PluginContext,
) -> Result<String, SsgError>
fn transform_html( &self, html: &str, _path: &Path, _ctx: &PluginContext, ) -> Result<String, SsgError>
Source§fn has_transform(&self) -> bool
fn has_transform(&self) -> bool
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
fn needs_all_files(&self) -> bool
true if this plugin must always observe the full
cache.html_files() list — even during --incremental
rebuilds that only invalidated a handful of pages. Read moreAuto Trait Implementations§
impl Freeze for ImageOptimizationPlugin
impl RefUnwindSafe for ImageOptimizationPlugin
impl Send for ImageOptimizationPlugin
impl Sync for ImageOptimizationPlugin
impl Unpin for ImageOptimizationPlugin
impl UnsafeUnpin for ImageOptimizationPlugin
impl UnwindSafe for ImageOptimizationPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more