Can we please have a fix for this as part of Hugo? There are so many people who are having issues with this.
It is very annoying to configure editors to not insert an empty line at the end of each file. I tried VSCode, vim, TextEdit, nano (with --nonewlines flag!), and each of them gave me the empty newline.
@razon I don’t think that will solve this particular issue, which I guess could look something like this:
<a href="foo">Foo</foo>
If an editor (or Prettier) insists on adding a trailing newline to every file, I don’t see how you currently can avoid it in the above.
I would gladly add something to Hugo to fix this if someone can come up with a reasonably simple thing. I’m not sure if we can “chomp” the newline of all these hook templates, there may be people that need those.
For future reference, if you are on macOS, you need to install GNU Nano because the default nano on macOS does not have the -L or --nonewlines option.
After
brew install nano
You need to add
export PATH="$(brew --prefix nano)/bin:$PATH"
to your ~/.zshrc so it uses the newly installed GNU Nano. Use which nano to confirm. Then you can remove the newline by editing the file with the aforementioned command line option.
The @razon solution is good, I tried your code with {{- or -}} everywhere, and the trick {{- "" -}} at the last line (or with an extra blank line), and it works.