I'm trying to use relative_url in most of the links of my Jekyll theme, so if someone wants to have this theme working in a subdirectory he can do it. I have a problem with the list of categories of the post, each of which should link to the archive.
In _layouts/post.html I have this code:
{% if site.data.settings.categories.active %}
{% include categories.html %}
{% endif %}
categories.html has this code:
<div class="categories">
<span><p>Categories:</p>
{% if post %}
{% assign categories = post.categories %}
{% else %}
{% assign categories = page.categories %}
{% endif %}
{% for category in categories %}
<a href="{{ "/categories/#{{category | slugify}}" | relative_url}}">{{category}}</a>
{% unless forloop.last %} {% endunless %}
{% endfor %}
</span>
</div>
Here's the problem:
<a href="{{ "/categories/#{{category | slugify}}" | relative_url}}">{{category}}</a>
Somehow, this returns the current post url.
<a href="/categories/#{{category | slugify}}">{{category}}</a>
This returns the correct link, but does not work in case the site is in a subdirectory.
Why it returns the post url?