Add better errors for minifying and upgrade crate
This commit is contained in:
parent
826e701b4f
commit
5a61139719
|
@ -8,7 +8,7 @@ include = ["src/**/*"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tera = "1"
|
tera = "1"
|
||||||
glob = "0.3"
|
glob = "0.3"
|
||||||
minify-html = "0.3.6"
|
minify-html = "0.3.8"
|
||||||
rayon = "1"
|
rayon = "1"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_derive = "1"
|
serde_derive = "1"
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex, RwLock};
|
||||||
|
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use minify_html::{truncate, Cfg};
|
use minify_html::{with_friendly_error, Cfg};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use tera::{Context, Tera};
|
use tera::{Context, Tera};
|
||||||
|
|
||||||
|
@ -450,13 +450,13 @@ impl Site {
|
||||||
fn minify(&self, html: String) -> Result<String> {
|
fn minify(&self, html: String) -> Result<String> {
|
||||||
let cfg = &Cfg { minify_js: false };
|
let cfg = &Cfg { minify_js: false };
|
||||||
let mut input_bytes = html.as_bytes().to_vec();
|
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(_len) => match std::str::from_utf8(&mut input_bytes) {
|
||||||
Ok(result) => Ok(result.to_string()),
|
Ok(result) => Ok(result.to_string()),
|
||||||
Err(err) => bail!("Failed to convert bytes to string : {}", err),
|
Err(err) => bail!("Failed to convert bytes to string : {}", err),
|
||||||
},
|
},
|
||||||
Err(minify_error) => {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Next line is meant to test inner html chars (see https://github.com/getzola/zola/issues/1152) -->
|
||||||
|
<p> <<< </p>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
|
|
Loading…
Reference in New Issue