Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 140 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions components/config/src/config/image_compression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ImageFormat {
Jpeg,
Webp,
Avif,
}

impl ImageFormat {
pub fn file_extension(&self) -> &str {
match self {
ImageFormat::Jpeg => "jpg",
ImageFormat::Webp => "webp",
ImageFormat::Avif => "avif",
}
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ImageCompression {
/// Glob of files to run the compression on.
pub glob: String,
/// The codec to encode files to.
pub format: ImageFormat,
/// Target SSIM score.
#[serde(default = "default_ssim")]
pub target_ssim: f64,
/// Number of iterations to try and reach target SSIM.
#[serde(default = "default_iterations")]
pub max_iterations: u8,
}

fn default_ssim() -> f64 {
0.8295
}

fn default_iterations() -> u8 {
5
}
3 changes: 3 additions & 0 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod image_compression;
pub mod languages;
pub mod link_checker;
pub mod markup;
Expand Down Expand Up @@ -77,6 +78,7 @@ pub struct Config {
pub compile_sass: bool,
/// Whether to minify the html output
pub minify_html: bool,
pub compress_images: Option<Vec<image_compression::ImageCompression>>,
/// Whether to build the search index for the content
pub build_search_index: bool,
/// A list of file glob patterns to ignore when processing the content folder. Defaults to none.
Expand Down Expand Up @@ -466,6 +468,7 @@ impl Default for Config {
author: None,
compile_sass: false,
minify_html: false,
compress_images: None,
mode: Mode::Build,
build_search_index: false,
ignored_content: Vec::new(),
Expand Down
1 change: 1 addition & 0 deletions components/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::Path;

pub use crate::config::{
Config,
image_compression::{ImageCompression, ImageFormat},
languages::LanguageOptions,
link_checker::LinkChecker,
link_checker::LinkCheckerLevel,
Expand Down
3 changes: 3 additions & 0 deletions components/site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ content = { workspace = true }
render = { workspace = true }
markdown = { workspace = true }
memchr = { workspace = true }
perceptual-image = { version = "0.1.0", features = ["jpeg", "avif", "webp"] }
image.workspace = true
aho-corasick = "1.1.4"

[dev-dependencies]
tempfile = "3"
Expand Down
Loading