Browse Source

Extract category_link filter from category_generator.rb plugin

Allows category_link to be used as a filter to display a link to
any category.
unreleased_contents
David Tchepak 13 years ago
parent
commit
02dac280d0
  1. 16
      plugins/category_generator.rb

16
plugins/category_generator.rb

@ -141,10 +141,7 @@ module Jekyll
# Returns string # Returns string
# #
def category_links(categories) def category_links(categories)
dir = @context.registers[:site].config['category_dir'] categories = categories.sort!.map { |c| category_link c }
categories = categories.sort!.map do |item|
"<a class='category' href='/#{dir}/#{item.gsub(/_|\P{Word}/, '-').gsub(/-{2,}/, '-').downcase}/'>#{item}</a>"
end
case categories.length case categories.length
when 0 when 0
@ -156,6 +153,17 @@ module Jekyll
end end
end end
# Outputs a single category as an <a> link.
#
# +category+ is a category string to format as an <a> link
#
# Returns string
#
def category_link(category)
dir = @context.registers[:site].config['category_dir']
"<a class='category' href='/#{dir}/#{category.gsub(/_|\P{Word}/, '-').gsub(/-{2,}/, '-').downcase}/'>#{category}</a>"
end
# Outputs the post.date as formatted html, with hooks for CSS styling. # Outputs the post.date as formatted html, with hooks for CSS styling.
# #
# +date+ is the date object to format as HTML. # +date+ is the date object to format as HTML.

Loading…
Cancel
Save