I've been using Octopress for a while, but I haven't pulled upstream changes for ages. I just made a new local branch to do so, and the merging was pretty painless, but one problem I have is that my category names are now downcased everywhere. This didn't use to happen, and it's a problem for me because I colorize links differently based on the category of each post, using the following:
{% capture category_class %}
{% for category in post.categories %}
{{ category | prepend:'category-' }}
{% endfor %}
{% endcapture %}
# ...
<div class="{{ category_class | strip_newlines }}">
Here, the category_class ends up being something like "category-coding" even though the category is specified in the post source as Coding, with a capital C. Now, I could just change my SASS to use lowercase category names for the classes... but then my category names would still be lowercase everywhere else, and I'd prefer them not to be.
So I'd like to remove this downcasing of category names throughout Octopress. But I can't for the life of me figure out where it is actually happening. (It probably doesn't help that I don't know Ruby.)
There's a downcase
call in Jekyll which produces the lowercased categories:
https://github.com/jekyll/jekyll/blob/v2.5.3/lib/jekyll/post.rb#L83
def populate_categories
categories_from_data =
Utils.pluralized_array_from_hash(data, 'category', 'categories')
self.categories = (Array(categories) +
categories_from_data).map {|c| c.to_s.downcase}.flatten.uniq
end
There doesn't seem to be any other way to access the categories array within a post. You would need to modify or monkey patch Jekyll yourself or just use Javascript or CSS (text-transform
) to re-capitalize.
It seems Octopress also supports plugins, so that could be one more solution if you want to do some custom Ruby hacking. I.e. create a capitalized categories plugin.