daviddarnes / alembic

⚗️ A Jekyll boilerplate theme designed to be a starting point for any Jekyll website
https://alembic.darn.es
MIT License
754 stars 894 forks source link

[Bug]: Categories with spaces are inconsistently slugified #173

Closed jimgraham closed 3 years ago

jimgraham commented 3 years ago

Summary

With a category in a page such as "Development Manager", when the category is linking in the metadata without being slugified. In the category page, however, the category name is slugified. This creates an inconsistency that prevents linking from the metadata link to the category.

To Reproduce

Steps to reproduce the behaviour:

  1. Create a blog post with a category with a space: e.g. categories: [Tech, Development Manager]
  2. Navigate to page.
  3. Click on the "Development Manager" category link
  4. Navigation takes you to the head of the Category page.

Expected behaviour

Expect the link / navigation to take you to the correct <h2> heading for the category ("Development Manager")

Environment

Possible fix:

I've fixed this on my blog (https://jim-graham.net/categories) by adding slugify to post-meta.html

{% if page.categories %}
  {% capture categories %}
    {% for category in page.categories %}
      <span class="label  label--category"><a href="{{ site.baseurl }}/categories/#{{ category | downcase | slugify }}">{{ category }}</a></span>{% if forloop.last == false %},{% endif %}
    {% endfor %}
  {% endcapture %}
{% elsif page.category %}
  {% capture categories %}
    <span class="label  label--category"><a href="{{ site.baseurl }}/categories/#{{ page.category | downcase | slugify }}">{{ page.category }}</a></span>
  {% endcapture %}
{% endif %}