jekyll-archives
jekyll-archives copied to clipboard
Provide link helper
It would be nice to have a archive_url liquid helper we can use to generate the link to a specific archive.
I saw #35 but the solution is definitely not optimal. The code will execute a nested loop for each generated page.
Would this be something like post_url? What use cases do you have in mind?
The code will execute a nested loop for each generated page.
Who cares about this?
Who cares about this?
I partially do. But the main issue, is that in order to add a simple link like I was doing with jekyll-categories gem, I now have to write almost 5 lines of code instead of using one single helper.
Here's a diff of the change that gives you a better idea of the use case.

I see. The reason I haven't implemented this is because different people need different customizations to how the link is displayed (display text, contents, classes, etc.). Similarly, there's no helper to list posts and pages in Jekyll core.
If you are using this category listing quite often, I would recommend putting it in an include and just referencing that every time.
The helper I was talking about doesn't really apply any formatting. It just generates the archive URL. Specifically, I was looking for the equivalent of category_url in
{% category_url category %}
That would be enough.
Hmm... That seems like quite a simple function, though, since all permalinks are set in the configuration and are not overridable by individual categories (unlike posts).
So that would really be equivalent to just putting /category/{{ category }}, but I do see your point in not wanting to duplicate this too many times.
I am open to a PR if you want to code one up; otherwise, I might get around to it sometime after my exams are done (early May).
I came up with this hack. Basically read the format from _config.yml and do some string replacement to replace the placeholder variable with the slugified category.
{% for category in site.data.categories %}
{% capture category_slug %}{{ category | slugify }}{% endcapture %}
<li>
<a href="{{ site['jekyll-archives'].permalinks.category | replace: ':name', category_slug }}">{{ category }}</a>
</li>
{% endfor %}