Add HTML minification.
This commit is contained in:
parent
9bfc8477be
commit
774e1411bb
|
@ -17,6 +17,7 @@ path = "source/main.rs"
|
|||
askama = "0.11.1"
|
||||
color-eyre = "0.6.2"
|
||||
comrak = "0.15.0"
|
||||
minify-html = "0.10.7"
|
||||
rsass = "0.23.4"
|
||||
toml-frontmatter = "0.1.0"
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::{
|
|||
use color_eyre::{install, Result};
|
||||
|
||||
mod copy;
|
||||
mod minify;
|
||||
mod scss;
|
||||
mod templates;
|
||||
mod video;
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -21,7 +21,7 @@ impl Index {
|
|||
page_title: "Bauke".to_string(),
|
||||
};
|
||||
|
||||
write(destination, template.render()?)?;
|
||||
write(destination, crate::minify::html(template.render()?)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -68,7 +68,11 @@ pub fn write_all(public_dir: &Path) -> Result<()> {
|
|||
speedrun: video_data.speedrun,
|
||||
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(())
|
||||
|
|
Loading…
Reference in New Issue