Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Octopress plugin to generate a month list.
# encoding: utf-8
#
# Month List for Octopress
module Jekyll
class MonthList < Liquid::Tag
def initialize(tag_name, markup, tokens)
@opts = {}
if markup.strip =~ /\s*counter:(\w+)/i
@opts['counter'] = ($1 == 'true')
markup = markup.strip.sub(/counter:\w+/i,'')
end
super
end
def render(context)
html = ""
posts = context.registers[:site].posts.reverse
posts = posts.group_by{|c| {"month" => c.date.month, "year" => c.date.year}}
posts.each do |period, post|
month_dir = "/#{period["year"]}/#{"%02d" % period["month"]}/"
html << "<li><a href='#{month_dir}'>#{period["year"]}-#{"%02d" % period["month"]}"
html << " (#{post.count})" if @opts['counter']
html << "</a></li>"
end
html
end
end
end
Liquid::Template.register_tag('month_list', Jekyll::MonthList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.