require 'middleman-blog/custom_pages'

module MoreDynamicCustomPages
  def initialize(property, app, controller, options)
    super
    @filter = options[:filter]
  end

  def manipulate_resource_list(resources)
    if @filter
      articles_by_property = @filter.call(@blog_data.articles)
      resources + articles_by_property.map do |property_value, articles|
        build_resource(link(property_value), property_value, articles)
      end
    else
      super
    end
  end
end

Middleman::Blog::CustomPages.send(:prepend, MoreDynamicCustomPages)

require 'middleman-blog/extension'

module AllowPaginatingCustomPages
  def after_configuration
    if options.custom_collections && options.paginate
      options.paginate = false
      super
      options.paginate = true
      require 'middleman-blog/paginator'
      @paginator = Middleman::Blog::Paginator.new(@app, self)
      @app.sitemap.register_resource_list_manipulator(:"blog_#{name}_paginate", @paginator, false)
    else
      super
    end
  end
end

Middleman::BlogExtension.send(:prepend, AllowPaginatingCustomPages)

Add extensions to custom pages in middleman-blog
Add extensions to custom pages in middleman-blog

The middleman-blog extension allows you to configure custom collections
of pages to allow you to generate pages for arbitrary groups of blog
articles.  The custom collections are based on keys in the the frontmatter.
For example defining a custom collection called "hats" would create a page
for each value of hats in the frontmatter of all the blog articles.  We'd
like to use this for authors rather than our custom proxy.  Unfortunately
our authors frontmatter is a list, so we'd get a page for each combination
of authors, which isn't quite what we want.  We want a page for each
individual author.

We customise Middleman::Blog::CustomPage to allow it to take a filter proc
that returns a hash of `{ value => [articles] }` which it then uses to
create the extra pages.  We also customise the Middleman::BlogExtension to
register the custom pages before the paginator so that we can take
advantage of the blog pagination on these pages.
