class Middleman::PostdatedExtension

Public Instance Methods

manipulate_resource_list(resources) click to toggle source

A Sitemap Manipulator

# File lib/middleman-postdated/extension.rb, line 11
def manipulate_resource_list(resources)
  resources.map(&method(:postdate))
end

Private Instance Methods

postdate(resource) click to toggle source
# File lib/middleman-postdated/extension.rb, line 17
def postdate(resource)
  # If it already has a date, we ignore it
  return resource if resource.data[:date]

  # Attempt to grab date from filename, and give up if we can't
  datestring = resource.path[%r{(?:^|/)(\d{4}-\d{2}-\d{2})-}, 1]
  return resource unless datestring

  date = Date.parse(datestring, "yyyy-mm-dd")
  # Add it to the :page metadata specifically
  resource.add_metadata :page => {:date => Time.utc(date.year, date.month, date.day, 10, 0, 0)}

  resource
end