pattex / jekyll-tagging

Jekyll plugin to automatically generate a tag cloud and tag pages.
385 stars 76 forks source link

Looks like it's broken with Jekyll 3.2.0 #51

Closed nhoizey closed 8 years ago

nhoizey commented 8 years ago

The plugin works well with Jekyll 3.1.6, but stops working when upgrading to Jekyll 3.2.0

{{ page | tags }} doesn't generate anything, and even breaks the rest of the generated HTML.

brandongoode commented 8 years ago

Same issue for me. {{ page | tags}} injects the full page HTML.

Tag page appears to still work correctly.

brandongoode commented 8 years ago

Manually building tag links works.

{% for tag in page.tags %}
  <a href="{{ site.baseurl }}/tag/{{tag | downcase}}/">{{tag}}</a>
{% endfor %}
nhoizey commented 8 years ago

@brandongoode IMHO, manually building tag links only uses Jekyll, not the plugin, that's why it works… ;-)

brandongoode commented 8 years ago

@nhoizey Completely agree. More of just a work around. The plugin still builds the tag pages for me, so that is still useful.

nhoizey commented 8 years ago

@brandongoode you should use slugify instead of downcase, if you have tags containing multiple words, special characters, or letters with accents, like I do.

brandongoode commented 8 years ago

@nhoizey good advice. I'm sure it will save me some headaches down the road. Thanks.

nhoizey commented 8 years ago

@brandongoode you're welcome!

ghost commented 8 years ago

If anyone is looking for something that will assign the set-<n> class to the tag links (so that each frequency is unique), I use this to generate the cloud:

{% capture tags %}
{% for tag in site.tags %}
{{ tag[1].size}}#{{ tag[0] }}
{% endfor %}
{% endcapture %}

{% assign sortedtags = tags | split: ' ' | sort %}

{% assign freqs = '' %}

{% for tag in sortedtags %}
{% assign tagitems = tag | split: '#' %}
{% unless freqs contains tagitems[0] %}
{% capture freqs %}
{{ freqs }}|{{ tagitems[0] }}
{% endcapture %}
{% endunless %}
{% endfor %}

{% assign freqs = freqs | remove_first: '|' | split: '|' %}
{% assign sets = '' %}
{% for freq in freqs %}

{% capture set %}

{% assign setsize = sets | split: "|" | size %}
{% capture a %}
{{ site.tag-var | times: forloop.index}}
{% endcapture %}

{% capture b%}
{{ setsize | times: freqs.size }}
{% endcapture %}

{% capture num %}
{{ a | minus: b}}
{% endcapture %}

{{ num | divided_by: freqs.size }}

{% endcapture %}
{% assign sets = sets | append: set%}
{% endfor %}

{% capture tags %}
{% for tag in site.tags %}
{{ tag[0] }}#{{ tag[1].size }}
{% endfor %}
{% endcapture %}

{% assign sortedtags = tags | split: ' ' | sort %}

{% for tag in sortedtags %}
{% assign tagitems = tag | split: '#' %}

{% assign counter = 0 %}
{% for freq in freqs %}
{% assign stripedfreq = freq | strip %}
{% if stripedfreq == tagitems[1] %}
{% assign splitsets = sets | split: ' ' %}
<a href="{{ site.baseurl }}/archive/tag/{{ tagitems[0] }}" class="set-{{ splitsets[counter] }}">{{ tagitems[0] }}</a>
{% endif %}
{% assign counter = counter | plus: 1 %}
{% endfor %}
{% endfor %}

Make sure to insert tag-var: 5 into your _config.yml, it controls how many sets there are. In this case, there will be 5 sets generated, with numbers 0-4. If you want 10 sets, insert tag-var: 10 instead.

It is probably more complicated than it has to be due to me not yet fully grasping how arrays work in liquid, but it works for me (but if anyone has any suggestions to clean it up, I will happily take them).

I then use jekyll-archives to generate the tag pages.

I believe that this covers the full functionality offered by this plugin (cloud generation with set classes, tag page generation) except for the feeds feature.

WillyPillow commented 8 years ago

Adding Liquid::Template.register_filter(Jekyll::Filters) after require 'jekyll/tagging' seems to be a quick fix.

tohuw commented 8 years ago

@pattex, why does @WillyPillow's workaround fix it, and how can this be manifested into the gem?

WillyPillow commented 8 years ago

@tohuw My guess is that in 3.2.0, Jekyll doesn't enable plugin filters unless explicitly registered, while the previous versions did. Keep in mind that I'm far from familiar with Jekyll and this is just a rough guess :)

pattex commented 8 years ago

Yes, @WillyPillow is right. Filters have to be registered. I just fixed it in d58fd53.

Thanks a lot and greetings pattex - the worst open source maintainer of the galaxy

nhoizey commented 8 years ago

Awesome, thanks!

No waiting for the release on Rubygems… ;-)

(You're not the worst maintainer, obviously!)