1
Fork 0
bauke-xyz/source/minify.rs

27 lines
826 B
Rust
Raw Permalink Normal View History

//! Code for minifying.
2023-01-09 14:43:05 +00:00
use color_eyre::Result;
/// Minify HTML using [`minify-html`].
2023-01-09 14:43:05 +00:00
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,
2024-01-15 15:31:42 +00:00
keep_input_type_text_attr: true,
2023-01-09 14:43:05 +00:00
keep_spaces_between_attributes: true,
2024-01-15 15:31:42 +00:00
keep_ssi_comments: false,
2023-01-09 14:43:05 +00:00
minify_css: false,
minify_js: false,
2024-01-15 15:31:42 +00:00
preserve_brace_template_syntax: false,
preserve_chevron_percent_template_syntax: false,
2023-01-09 14:43:05 +00:00
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)
}