jekyll-archives icon indicating copy to clipboard operation
jekyll-archives copied to clipboard

Provide link helper

Open weppos opened this issue 10 years ago • 8 comments

It would be nice to have a archive_url liquid helper we can use to generate the link to a specific archive.

weppos avatar Mar 13 '15 18:03 weppos

I saw #35 but the solution is definitely not optimal. The code will execute a nested loop for each generated page.

weppos avatar Mar 13 '15 18:03 weppos

Would this be something like post_url? What use cases do you have in mind?

alfredxing avatar Mar 16 '15 23:03 alfredxing

The code will execute a nested loop for each generated page.

Who cares about this?

hazzik avatar Mar 17 '15 01:03 hazzik

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.

screen shot 2015-03-17 at 10 05 17

weppos avatar Mar 17 '15 09:03 weppos

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.

alfredxing avatar Mar 17 '15 15:03 alfredxing

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.

weppos avatar Mar 17 '15 17:03 weppos

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).

alfredxing avatar Apr 05 '15 18:04 alfredxing

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 %}

yangshun avatar Jun 08 '17 10:06 yangshun