Skip to content

Instantly share code, notes, and snippets.

@derky1202
Forked from nistude/category_list.rb
Created January 23, 2012 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derky1202/1661725 to your computer and use it in GitHub Desktop.
Save derky1202/1661725 to your computer and use it in GitHub Desktop.
A category list tag for jekyll
# place this file in your plugins directory and add the tag to your sidebar
#$ cat source/_includes/asides/categories.html
#<section>
# <h1>Categories</h1>
# <ul id="categories">
# {% category_list %}
# </ul>
#</section>
module Jekyll
class CategoryListTag < Liquid::Tag
def render(context)
html = ""
categories = context.registers[:site].categories.keys
categories.sort.each do |category|
posts_in_category = context.registers[:site].categories[category].size
html << "<li class='category'><a href='http://colors4.us/blog/categories/#{category}/'>#{category} (#{posts_in_category})</a></li>\n"
end
html
end
end
end
Liquid::Template.register_tag('category_list', Jekyll::CategoryListTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment