class Middleman::Blog::CustomPages

This adds new summary pages for arbitrarily defined blog article properties

Attributes

property[R]

Public Class Methods

new(property, app, controller, options) click to toggle source
# File lib/middleman-blog/custom_pages.rb, line 11
def initialize(property, app, controller, options)
  @property = property
  @sitemap = app.sitemap
  @blog_controller = controller
  @blog_data = controller.data
  @link_template = uri_template options[:link]
  @page_template = options[:template]
end

Public Instance Methods

manipulate_resource_list(resources) click to toggle source
# File lib/middleman-blog/custom_pages.rb, line 27
def manipulate_resource_list(resources)
  articles_by_property = @blog_data.articles
                                   .select { |a| a.data[property] }
                                   .group_by { |a| a.data[property] }
  resources + articles_by_property.map do |property_value, articles|
    build_resource(link(property_value), property_value, articles)
  end
end

Private Instance Methods

build_resource(path, value, articles) click to toggle source
# File lib/middleman-blog/custom_pages.rb, line 38
def build_resource(path, value, articles)
  articles = articles.sort_by(&:date).reverse
  Sitemap::ProxyResource.new(@sitemap, path, @page_template).tap do |p|
    p.add_metadata locals: {
      'page_type' => property.to_s,
      property => value,
      'articles' => articles,
      'blog_controller' => @blog_controller
    }
  end
end