Skip to content

Commit

Permalink
Add better errors for minifying and upgrade crate
Browse files Browse the repository at this point in the history
  • Loading branch information
areille committed Sep 7, 2020
1 parent 1b6a06f commit d16dea7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test_site/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ <h3 class="post__title"><a href="{{ page.permalink }}">{{ page.title }}</a></h3>
</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 %}
Expand Down

0 comments on commit d16dea7

Please sign in to comment.