The minify tool used by hugo to minify the output works great on HTML, but there have been several issues with it destroying inlined SVGs:
These issues stem from the fact that minify changes the svg <path> attributes and attempts to optimize the drawing of lines on the svg canvas. This is a very hard problem, and as a result hugo users are affected by SVG optimization bugs from time to time. Furthermore, the testing for SVG minification in the minify repo seems to still be rudimentary: https://github.com/tdewolff/minify/blob/master/svg/pathdata_test.go
In minify project readme https://github.com/tdewolff/minify it says:
"Status: SVG: partially implemented; in development"
I think in light of this, we should add an option to disable inline SVG minification, or - even better - be able to pass options through to minify if another class of problems emerges.
I suggest we add a new minify config struct. As we use the same minifier setup for both --minify and the minify template func, there is some thinking to be done how to disable one but not the other.
The bug has been fixed. I appreciate the report.
This is a very hard problem
Actually it's a fairly easy problem. The only thing that makes it hard is making it remotely fast, which requires a lot of byte fiddling which is very bug prone. The HTML minifier has had a lot more testing in this regard so it's no surprise that it is more stable. The SVG test set is fairly complete to be honest so I'm not sure what you mean with rudimentary. Bugs creep in but that is normal in any piece of software.
The phrase "partially implemented; in development" means just that: thus far it should be production ready but there is still a lot of potential to minify further. Same goes for the JS minifier.
Dear @tdewolff, thanks for your quick bugfix & immediate response to this issue!
I think minify is a great project. But as you said there are still potential future issues (speed / byte fiddling) with some aspects of the tool.
Therefore it'd be great if we could have a choice which formats to minify when calling it from within the hugo toolchain.
Most helpful comment
I suggest we add a new
minifyconfig struct. As we use the same minifier setup for both--minifyand theminifytemplate func, there is some thinking to be done how to disable one but not the other.