I am using the Royce theme for my Jekyll blog and I’ve spent the weekend trying to set up categories to work alongside the theme supported tags. While I was implementing some new code features I thought I’d tidy up some of the existing code because scruffy indentation is quite bothersome.

The code started in this ugly fashion:

{% capture site_tags %}{% for tag in site.tags %}{{ tag | first }}{% unless forloop.last %},{% endunless %}{% endfor
%}{%
endcapture %} {% assign sortedTags = site_tags | split:',' | sort %}

and refactored like so:

{% capture site_tags %}
  {% for tag in site.tags %}
      {{ tag | first }}
      {% unless forloop.last %},
      {% endunless %}
  {% endfor %}
{% endcapture %}
{% assign sortedTags = site_tags | split:',' | sort %}

Inspecting the sortedTags variable with {{ sortedTags | inspect }}

Leads to this horror of newline proliferation:

["\n \n raspberry_pi\n ", "\n \n \n FIRE\n ", "\n \n \n bash\n ", "\n \n \n command-line\n ", "\n \n \n docker\n ", "\n \n \n exercism\n ", "\n \n \n financial-planning\n ", "\n \n \n git\n ", "\n \n \n javascript\n ", "\n \n \n jekyll\n \n \n ", "\n \n \n jq\n ", "\n \n \n learned-today\n ", "\n \n \n makers-bootcamp\n ", "\n \n \n node_modules\n ", "\n \n \n presentation\n ", "\n \n \n project\n ", "\n \n \n python\n ", "\n \n \n rails\n ", "\n \n \n resources\n ", "\n \n \n retirement\n ", "\n \n \n ruby\n ", "\n \n \n spreadsheet\n ", "\n \n \n tips\n "]

I only noticed the problem because I was trying to produce a list of posts grouped by tag and nothing was being returned.

Turns out that spacious formatting causes problems with paragraph breaks appearing in wrong places. So ugly formatting it is!