1
Fork 0

Add HTML minification.

This commit is contained in:
Bauke 2023-01-09 15:43:05 +01:00
parent 9bfc8477be
commit 774e1411bb
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
5 changed files with 30 additions and 2 deletions

View File

@ -17,6 +17,7 @@ path = "source/main.rs"
askama = "0.11.1" askama = "0.11.1"
color-eyre = "0.6.2" color-eyre = "0.6.2"
comrak = "0.15.0" comrak = "0.15.0"
minify-html = "0.10.7"
rsass = "0.23.4" rsass = "0.23.4"
toml-frontmatter = "0.1.0" toml-frontmatter = "0.1.0"

View File

@ -6,6 +6,7 @@ use std::{
use color_eyre::{install, Result}; use color_eyre::{install, Result};
mod copy; mod copy;
mod minify;
mod scss; mod scss;
mod templates; mod templates;
mod video; mod video;

22
source/minify.rs Normal file
View File

@ -0,0 +1,22 @@
use color_eyre::Result;
/**
Minify HTML using [`minify_html`].
*/
pub fn html(data: String) -> Result<String> {
let minify_config = minify_html::Cfg {
do_not_minify_doctype: true,
ensure_spec_compliant_unquoted_attribute_values: true,
keep_closing_tags: true,
keep_comments: false,
keep_html_and_head_opening_tags: true,
keep_spaces_between_attributes: true,
minify_css: false,
minify_js: false,
remove_bangs: false,
remove_processing_instructions: false,
};
let minified_data = minify_html::minify(&data.into_bytes(), &minify_config);
String::from_utf8(minified_data).map_err(Into::into)
}

View File

@ -21,7 +21,7 @@ impl Index {
page_title: "Bauke".to_string(), page_title: "Bauke".to_string(),
}; };
write(destination, template.render()?)?; write(destination, crate::minify::html(template.render()?)?)?;
Ok(()) Ok(())
} }

View File

@ -68,7 +68,11 @@ pub fn write_all(public_dir: &Path) -> Result<()> {
speedrun: video_data.speedrun, speedrun: video_data.speedrun,
video_id: video_data.id, video_id: video_data.id,
}; };
fs::write(video_dir.join("index.html"), template.render()?)?;
fs::write(
video_dir.join("index.html"),
crate::minify::html(template.render()?)?,
)?;
} }
Ok(()) Ok(())