HUGO

"hugo --minify" strips spaces and preserve some new lines

When I use hugo --minify in my branch/repo:

  1. some new lines are not minified,
  2. some spaces are striped.

Window 000222
Window 000224 Window 000223

This might be related to https://discourse.gohugo.io/t/hugo-minify-strips-out-p-tags/.

If a maintainer confirms this is a buggy/unwanted behavior, I can open an issue in tdewolff/minify if it’s what needs to be done.

Someone has any insight on this?

I’m looking for some insight on this as well, in my case I don’t have a problem with spaces being removed (as long as it’s not between words) but for some reason some new lines still get generated. Seems to happen inside a {{ range }}, I tried removing the indentation inside the range but it didn’t work

Author of minify here. In general a lack of newlines does not mean it is minified well! You will actually see that other minifiers would use a space instead of a newline, which results in the same file size. Whitespace (space or newline) is significant between phrasing elements (such as the A tag), so these space must be preserved in the same way we preserve spaces between words.

Other insignificant whitespace is always removed (unless you use display:block on an inline element and then depend on whitespace for element positioning … BAD!).

If you think a space could be removed safely or a whitespace is removed that is unsafe, please report a bug at the minify github!

I noticed this behavior as well, for example in this case with a Font Awesome placeholder.

<div class="post__meta">
      <i class="fas fa-calendar-alt"></i> {{ .Date.Format (.Site.Params.dateformat | default "Jan 02, 2006") }}
</div>

I don’t use the JS framework, only the CSS integration of Font Awesome 5, which relies on the ::before pseudo element content with an hexadecimal refering to a character in a font file. With the minification the space between the i element and the date disappears.

Yes this is a valid problem that should be fixed in the minifier (though I’d argue this a bad design from the Font Awesome package actually!). See https://github.com/tdewolff/minify/issues/240

Actually Font Awesome is one example, but the pseudo element content CSS property is used in various places, it could be quotes for blockquote element, etc.