Reputation: 34939
Since I have updated Jekyl to 0.12.0
my site doesn't compile anymore. Everywhere I have code like this, looping through post and filtering a category it fails
<ul>
{% for post in site.posts reversed %}
{% if post.category[0] == "about" %}
<li>
<a href="{{base_path}}{{post.url}}">{{ post.title }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
This is the error message that I get:
Liquid Exception: undefined method `gsub' for ["about"]:Array in 2012-09-20-about.md
If I remove Jekyll 0.12.0
then everything works again.
Has something changed in a drastic way?
Upvotes: 1
Views: 154
Reputation: 12707
I think you must have some posts without any categories defined?
I believe Jekyll 0.12.0 made the standards for error catching higher. So if a post has no categories, the Ruby command post.category[0] == about
doesn't throw FALSE
, it throws NA
(or something like that). Before, Jekyll would just ignore this (presumably treating it as FALSE
), which isn't really the best behavior.
My guess is that you should rewrite the command to be more explicit, i.e. if category[0] is not empty AND has value "about". Consider simply adding the extra if
statement before your command:
{% if defined?(post.category[0]) %}
To check that you're not making an invalid comparison first.
Upvotes: 1
Reputation: 4002
Hmmm, I can't reproduce the error here. If you change it to
{% if post.category contains "about" %}
does it work?
Upvotes: 0