Hi, friends
So, I’m new to jekyll and programming stuff. I’m building a blog in 3 languages, with a variable ‘lang’ in every post that identifies it (br, en or es).
I have a piece of code that shows all the tags (in all languages, and with the number of posts of each category in superscript), and by clicking them, it lists the posts in that tag. That’s the original code:
{%- assign _tag_max_size = 1 -%}
{%- assign _tag_min_size = 1 -%}
{%- assign _tag_cur_size = 1 -%}
{%- assign _tags = site.tags -%}
{%- for _tag in _tags | sort -%}
{%- assign _tag_cur_size = _tag | size -%}
{%- if _tag_cur_size > _tag_max_size -%}
{%- assign _tag_max_size = _tag_cur_size -%}
{%- endif -%}
{%- if _tag_cur_size < _tag_min_size -%}
{%- assign _tag_min_size = _tag_cur_size -%}
{%- endif -%}
{%- endfor -%}
{%- assign _tag_gap_size = _tag_max_size | minus: _tag_min_size | plus: 1 | divided_by: 4 -%}
{%- if _tag_gap_size < 1 -%}
{%- assign _tag_gap_size = 1 -%}
{%- endif -%}
<div class="site-tags js-tags">
<ul class="menu">
{%- assign poste = site.posts | where: 'lang', page.lang -%}
{%- if page.lang == 'br' -%}
<li>
<button type="button" class="button button--secondary button--pill tag-button tag-button--all" data-encode="">
Mostrar todos<div class="tag-button__count">{{ poste | size }}</div>
</button>
</li>
{%- elsif page.lang == 'en' -%}
<li>
<button type="button" class="button button--secondary button--pill tag-button tag-button--all" data-encode="">
Show all<div class="tag-button__count">{{ poste | size }}</div>
</button>
</li>
{%- else -%}
<li>
<button type="button" class="button button--secondary button--pill tag-button tag-button--all" data-encode="">
Mostrar todos<div class="tag-button__count">{{ poste | size }}</div>
</button>
</li>
{%- endif -%}
{%- for _tag in _tags -%}
{%- assign _tag_cur_size = _tag | size -%}
{%- assign _tag_min_1 = _tag_min_size -%}
{%- assign _tag_max_1 = _tag_min_1 | plus: _tag_gap_size -%}
{%- assign _tag_min_2 = _tag_max_1 -%}
{%- assign _tag_max_2 = _tag_min_2 | plus: _tag_gap_size -%}
{%- assign _tag_min_3 = _tag_max_2 -%}
{%- assign _tag_max_3 = _tag_min_3 | plus: _tag_gap_size -%}
{%- assign _tag_min_4 = _tag_max_3 -%}
{%- assign _tag_max_4 = _tag_min_4 | plus: _tag_gap_size -%}
{%- if _tag_cur_size >= _tag_min_1 and _tag_cur_size < _tag_max_1 -%}
{%- assign _c_index = 1 -%}
{%- elsif _tag_cur_size >= _tag_min_2 and _tag_cur_size < _tag_max_2 -%}
{%- assign _c_index = 2 -%}
{%- elsif _tag_cur_size >= _tag_min_3 and _tag_cur_size < _tag_max_3 -%}
{%- assign _c_index = 3 -%}
{%- elsif _tag_cur_size >= _tag_min_4 and _tag_cur_size < _tag_max_4 -%}
{%- assign _c_index = 4 -%}
{%- else -%}
{%- assign _c_index = 4 -%}
{%- endif -%}
<li><button type="button" class="button button--pill tag-button tag-button-{{ _c_index }}" data-encode="{{ _tag[0] | strip | url_encode }}">
<span> {{ _tag[0] }} </span><div class="tag-button__count">{{ _tag[1].size }}</div>
</button>
{%- endfor -%}
</li>
</ul>
</div>
I’d like to filter the tags, to show only the ones in the user’s language. I’ve tried to change the 4th line to this:
{%- assign _tags = site.posts | where: 'lang', page.lang | map: 'tags' | uniq | sort -%}
But it doesn’t recognize apropriately the ‘uniq’ filter, not listing the posts correctly. If I do the same without ‘uniq’, it generates correctly (only the tags in the correct language, and generating the respective posts), but with duplicated tags (one tag per post).
That’s the website blog listing page:
https://gustavosabbag.github.io/en/articles.html
And this is the repository, directly to the html file that’s generating the tags:
https://github.com/gustavosabbag/gustavosabbag.github.io/blob/master/_includes/tags.html
Can someone help me, please?