Last active
August 29, 2015 13:56
-
-
Save yaasita/8918053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# | |
# Month List for Octopress | |
module Jekyll | |
class CatList < Liquid::Tag | |
def initialize(tag_name, markup, tokens) | |
super | |
end | |
def render(context) | |
html = "" | |
categories = context.registers[:site].categories | |
categories.each do |c,p| | |
html << "- [#{c}](#{p.first.site.config["url"]}blog/categories/#{c}/) (#{p.size})\n" | |
end | |
html | |
end | |
end | |
end | |
Liquid::Template.register_tag('category_list', Jekyll::CatList) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#使う場合 | |
{% month_list counter:true %} | |
{% category_list %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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_year = posts.group_by{|c| {"year" => c.date.year}} | |
posts_year.each do |period, post| | |
html << "- #{period["year"]}年(#{post.count})\n" | |
posts_month = posts.group_by{|c| {"month" => c.date.month, "year" => c.date.year}} | |
posts_month.each do |period, post| | |
html << " - #{"%02d" % period["month"]}月\n" | |
post.each do |p| | |
html << " - [#{p.data["title"]}](http://#{p.site.config["url"]}#{p.url}/)\n" | |
end | |
end | |
end | |
#posts = posts.group_by{|c| {"month" => c.date.month, "year" => c.date.year}} | |
#posts.each do |period, post| | |
# html << "- #{period["year"]}-#{"%02d" % period["month"]}" | |
# html << " (#{post.count})\n" if @opts['counter'] | |
# post.each do |p| | |
# #html << " - title = #{p.data["title"]}\n" | |
# html << " - name = #{p.url}\n" | |
# end | |
#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