Search code examples
htmlminify

html-minifier: Recursive but copying-over invalid files


I first met html-minifier today after running a small site I've created using Hugo through Google PageSpeed.

First thing I noticed is that although it does have recursion capabilities it stops working on unsupported files like images (my speakers started beeping and I freaked a little)

I've found this stack showing an apparently undocumented command-line option --file-ext

That worked perfectly but in the output directory, I noticed that the folders with the unmatching contents were gone.

From the directory root, I saw it was Hugo's folders for CSS, JS, images and Github Pages' CNAME file. Not only I can't tell for sure there's not even one piece of static file in any of the folders Hugo generated (you may know that Hugo is sometimes unpredictable) but also I would like to keep language specific XML Sitemaps I've created for some specific folders.

Long story short, is there a way to copy-over unmatching files "as is", keeping input directory ready for a commit/push?


Solution

  • After analyzing the whole directory structure I could be sure that within all the directory structure Hugo creates there are nothing more than HTML and XML files so then the Ockham's Razor took place.

    Since both my Hugo's source code and output contents are in totally different directories, it was a simple matter of pointing the output directory to the same path of the input directory.

    All HTML files are minified, overwriting those Hugo generated.