Add better errors for minifying and upgrade crate

This commit is contained in:
areille 2020-09-02 09:41:51 +02:00 committed by Vincent Prouillet
parent 826e701b4f
commit 5a61139719
3 changed files with 6 additions and 4 deletions

View File

@ -8,7 +8,7 @@ include = ["src/**/*"]
[dependencies]
tera = "1"
glob = "0.3"
minify-html = "0.3.6"
minify-html = "0.3.8"
rayon = "1"
serde = "1"
serde_derive = "1"

View File

@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex, RwLock};
use glob::glob;
use lazy_static::lazy_static;
use minify_html::{truncate, Cfg};
use minify_html::{with_friendly_error, Cfg};
use rayon::prelude::*;
use tera::{Context, Tera};
@ -450,13 +450,13 @@ impl Site {
fn minify(&self, html: String) -> Result<String> {
let cfg = &Cfg { minify_js: false };
let mut input_bytes = html.as_bytes().to_vec();
match truncate(&mut input_bytes, cfg) {
match with_friendly_error(&mut input_bytes, cfg) {
Ok(_len) => match std::str::from_utf8(&mut input_bytes) {
Ok(result) => Ok(result.to_string()),
Err(err) => bail!("Failed to convert bytes to string : {}", err),
},
Err(minify_error) => {
bail!("Failed to truncate html at character {}:", minify_error.position);
bail!("Failed to truncate html at character {}: {} \n {}", minify_error.position, minify_error.message, minify_error.code_context);
}
}
}

View File

@ -8,6 +8,8 @@
</article>
{% endfor %}
</div>
<!-- Next line is meant to test inner html chars (see https://github.com/getzola/zola/issues/1152) -->
<p> <<< </p>
{% endblock content %}
{% block script %}