Skip to content

Commit

Permalink
Rollup merge of #104404 - GuillaumeGomez:fix-missing-minification, r=…
Browse files Browse the repository at this point in the history
…notriddle

Fix missing minification for static files

It's a fix for #101702.

The problem was that `Path::ends_with` doesn't do what we thought it does: it checks if the entire item is the last path part, no just if the "path string" ends with the given argument. So instead, I just used the `extension()` method to get the information we want.

cc `@jsha`
r? `@notriddle`

PS: Is it worth it to add a CI test to ensure that the minification was performed on JS and CSS files or not?
  • Loading branch information
matthiaskrgr authored Nov 15, 2022
2 parents da2beab + e6baae5 commit f0978ee
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ impl StaticFile {
}

pub(crate) fn minified(&self) -> Vec<u8> {
if self.filename.ends_with(".css") {
let extension = match self.filename.extension() {
Some(e) => e,
None => return self.bytes.to_owned(),
};
if extension == "css" {
minifier::css::minify(str::from_utf8(self.bytes).unwrap()).unwrap().to_string().into()
} else if self.filename.ends_with(".js") {
} else if extension == "js" {
minifier::js::minify(str::from_utf8(self.bytes).unwrap()).to_string().into()
} else {
self.bytes.to_owned()
Expand Down

0 comments on commit f0978ee

Please sign in to comment.