#custom filters for Octopress module OctopressFilters def exerpt(input, url, url_text="Reade more…", permalink_text=false) if input.index(//i) input.split(//i)[0] + "
" elsif permalink_text input + "" else input end end def full_urls(input, url='') input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do $1+url+$3 end end def search_url(input) input.gsub /(http:\/\/)(\S+)/ do $2 end end def smart_quotes(input) require 'rubypants' RubyPants.new(input).to_html end def titlecase(input) require 'titlecase' input.titlecase end def datetime(date) if date.class == String date = Time.parse(date) end date end def ordinalize(date) date = datetime(date) "#{date.strftime('%B')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}" end def ordinal(number) if (11..13).include?(number.to_i % 100) "#{number}th" else case number.to_i % 10 when 1; "#{number}st" when 2; "#{number}nd" when 3; "#{number}rd" else "#{number}th" end end end #YearlyPost = Struct.new('YearlyPost', :year, :posts) def yearly_posts(site) #site.posts.reverse.group_by { |p| p.date.strftime("%Y") }.map { |k,v| YearlyPost.new(k,v) } site end end Liquid::Template.register_filter OctopressFilters