lib/nanoc/toolbox/helpers/blogging_extra.rb
# Enable blog post behavior on an item
#
# @param [Nanoc::Item] item the item that will act as a post
# @return [Nanoc::Item] the adapted item
#
# @example
#   items.each do |item|
#     act_as_post(item)
#   end
Enable blog post behavior on an item
Enable blog post behavior on an item
def act_as_post(item)
      fname = slug_for(item)
      if fname =~ /^\d+-\d+-\d+-/
        item[:year], item[:month], item[:day] = fname.split("-", 4)[0..2]
        item[:created_at] = Time.local(item[:year], item[:month], item[:day])
        item[:slug] = fname.sub(/^\d+-\d+-\d+-/,'')
      else
        item[:created_at] ||= Time.now
        item[:created_at] = attribute_to_time(item[:created_at])
        item[:year]  = item[:created_at].year
        item[:month] = item[:created_at].month
        item[:day]   = item[:created_at].day
      end
      item[:kind] = 'article'
      item[:comments] = true unless item[:comments] === false
      item
    end
def act_as_post ( item ) fname = slug_for ( item ) if fname =~ / ^ \d +- \d +- \d +- / item [ :year ] , item [ :month ] , item [ :day ] = fname . split ( "-" , 4 ) [ 0 .. 2 ] item [ :created_at ] = Time . local ( item [ :year ] , item [ :month ] , item [ :day ] ) item [ :slug ] = fname . sub ( / ^ \d +- \d +- \d +- / , '' ) else item [ :created_at ] ||= Time . now item [ :created_at ] = attribute_to_time ( item [ :created_at ] ) item [ :year ] = item [ :created_at ] . year item [ :month ] = item [ :created_at ] . month item [ :day ] = item [ :created_at ] . day end item [ :kind ] = 'article' item [ :comments ] = true unless item [ :comments ] === false item end
Enable blog post behavior on an item
Enable blog post behavior on an item
# get the date from the filename # Set creation date param from the values in the filename # Strip the date from the filename # get the date from # Add additional meta data # Enable comments unless specifically turned off
the adapted item
the adapted item
Nanoc::Item
item
item the item that will act as a post
item the item that will act as a post
example
items.each do |item| act_as_post(item) end
items . each do |item| act_as_post ( item ) end