Skip to content

Avoid linebreaks in Hugo shortcodes

Shortcodes in Hugo are a neat and poweful system to avoid repating the same piece of text over and over again. Let's say I have the following text:

Nunc in odio id magna molestie congue. Donec erat nulla, pulvinar eget volutpat non, molestie at nisi. Curabitur nec tristique felis. Cras imperdiet, ante et vestibulum iaculis, tellus ipsum pulvinar felis, at viverra est tellus et eros. In nec dignissim lectus, bibendum hendrerit ex. Praesent lobortis eget justo non vehicula.

Nulla et neque cursus libero tristique laoreet nec a ligula. Fusce sit “amet” scelerisque erat. Quisque lorem lectus, lobortis vitae mattis non, tincidunt sed felis. Donec sit “amet” erat nibh.

Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In et imperdiet dui. In ut enim pharetra, blandit purus vel, malesuada est. Morbi sollicitudin eget leo nec dignissim. Praesent sed leo quis purus pretium aliquet sed quis arcu. Pellentesque facilisis tellus nulla, dignissim laoreet quam maximus et.

And I want to link the "amet" word, then I can create a shortcode:

layouts/shortcodes/amet.html

And in this shortcode I place the text:

<a href="https://www.lipsum.com/feed/html">amet</a>

In the Markdown source this is:

Nulla et neque cursus libero tristique laoreet nec a ligula. Fusce sit "{{< amet >}}" scelerisque erat. Quisque lorem lectus, lobortis vitae mattis non, tincidunt sed felis. Donec sit "{{< amet >}}" erat nibh.

Pretty easy. However Hugo by default does a little bit too much: while generating the static content, it adds a line break. Which in the browser results in:

Nulla et neque cursus libero tristique laoreet nec a ligula. Fusce sit “amet ” scelerisque erat. Quisque lorem lectus, lobortis vitae mattis non, tincidunt sed felis. Donec sit “amet ” erat nibh.
                                                                            ^                                                                                                         ^

There is a nasty little space between the word and the quotation mark. The generated HTML source shows the problem:

  <p>Nunc in odio id magna molestie congue. Donec erat nulla, pulvinar eget volutpat non, molestie at nisi. Curabitur nec tristique felis. Cras imperdiet, ante et vestibulum iaculis, tellus ipsum pulvinar felis, at viverra est tellus et eros. In nec dignissim lectus, bibendum hendrerit ex. Praesent lobortis eget justo non vehicula.</p>
<p>Nulla et neque cursus libero tristique laoreet nec a ligula. Fusce sit &ldquo;<a href="https://www.lipsum.com/feed/html">amet</a>
&rdquo; scelerisque erat. Quisque lorem lectus, lobortis vitae mattis non, tincidunt sed felis. Donec sit &ldquo;<a href="https://www.lipsum.com/feed/html">amet</a>
&rdquo; erat nibh.</p>

Usually a line break in HTML is not a big deal, the browsers deal with that. But here an unnecessary space is added while rendering the content. Hugo makes it complicated to avoid this problem. There is no default setting to turn this off, however the shortcode can have an extra Hugo tag to avoid the training linebreak:

<a href="https://www.lipsum.com/feed/html">amet</a>{{- / Strip trailing newline. / -}}

By adding the {{- -}}, the training line break is not included in the final HTML output, and the quotation mark comes right after the shortcode content.

  • Twitter
  • Bookmark Avoid linebreaks in Hugo shortcodes at del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • Digg Avoid linebreaks in Hugo shortcodes
  • Bloglines Avoid linebreaks in Hugo shortcodes
  • Technorati Avoid linebreaks in Hugo shortcodes
  • Fark this: Avoid linebreaks in Hugo shortcodes
  • Bookmark Avoid linebreaks in Hugo shortcodes at YahooMyWeb
  • Bookmark Avoid linebreaks in Hugo shortcodes at Furl.net
  • Bookmark Avoid linebreaks in Hugo shortcodes at reddit.com
  • Bookmark Avoid linebreaks in Hugo shortcodes at blinklist.com
  • Bookmark Avoid linebreaks in Hugo shortcodes at Spurl.net
  • Bookmark Avoid linebreaks in Hugo shortcodes at Simpy.com
  • Bookmark Avoid linebreaks in Hugo shortcodes at blogmarks
  • Bookmark Avoid linebreaks in Hugo shortcodes with wists
  • wong it!
  • Bookmark using any bookmark manager!
  • Stumble It!
  • Identi.ca

Delete directories recursive on Hetzner Storage Box

Among other external solutions, I store some data on Storage Boxes from Hetzner. The Storage Box allows you to have sub-accounts, so for every server and system storing data there, I use a separate account. For each sub-account, one can select a subdirectory where the data is stored, and the sub-account then can only see this data. The Admin account can see all data, and see all directories.

The usual way I access the Storage Box from other systems is by using sftp protocol from ssh (don't confuse this with the "other" sftp). That's all good, until I remove a sub-account and want to delete the subdirectory with the data. The server doesn't know "rm -r" for recursive deletion, which means I have to traverse into every directory, delete all files, then delete the empty directories. And the encrypted backup I'm using is creating plenty of subdirectories.

Or I find a better tool.

 

Continue reading "Delete directories recursive on Hetzner Storage Box"
  • Twitter
  • Bookmark Delete directories recursive on Hetzner Storage Box at del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • Digg Delete directories recursive on Hetzner Storage Box
  • Bloglines Delete directories recursive on Hetzner Storage Box
  • Technorati Delete directories recursive on Hetzner Storage Box
  • Fark this: Delete directories recursive on Hetzner Storage Box
  • Bookmark Delete directories recursive on Hetzner Storage Box at YahooMyWeb
  • Bookmark Delete directories recursive on Hetzner Storage Box at Furl.net
  • Bookmark Delete directories recursive on Hetzner Storage Box at reddit.com
  • Bookmark Delete directories recursive on Hetzner Storage Box at blinklist.com
  • Bookmark Delete directories recursive on Hetzner Storage Box at Spurl.net
  • Bookmark Delete directories recursive on Hetzner Storage Box at Simpy.com
  • Bookmark Delete directories recursive on Hetzner Storage Box at blogmarks
  • Bookmark Delete directories recursive on Hetzner Storage Box with wists
  • wong it!
  • Bookmark using any bookmark manager!
  • Stumble It!
  • Identi.ca