Class: Middleman::Blog::TagPages

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-blog/tag_pages.rb

Overview

A sitemap plugin that adds tag pages to the sitemap based on the tags of blog articles.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, controller = nil) ⇒ TagPages

Returns a new instance of TagPages.



17
18
19
20
# File 'lib/middleman-blog/tag_pages.rb', line 17

def initialize(app, controller=nil)
  @app = app
  @blog_controller = controller
end

Class Method Details

Get a path to the given tag, based on the :taglink setting.

Parameters:

  • blog_options (Hash)
  • tag (String)

Returns:

  • (String)


12
13
14
# File 'lib/middleman-blog/tag_pages.rb', line 12

def link(blog_options, tag)
  ::Middleman::Util.normalize_path(blog_options.taglink.sub(':tag', tag.parameterize))
end

Instance Method Details

#blog_dataObject



22
23
24
25
26
27
28
# File 'lib/middleman-blog/tag_pages.rb', line 22

def blog_data
  if @blog_controller
    @blog_controller.data
  else
    @app.blog
  end
end

#blog_optionsObject



30
31
32
33
34
35
36
# File 'lib/middleman-blog/tag_pages.rb', line 30

def blog_options
  if @blog_controller
    @blog_controller.options
  else
    @app.blog.options
  end
end

#manipulate_resource_list(resources)

This method returns an undefined value.

Update the main sitemap resource list



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/middleman-blog/tag_pages.rb', line 40

def manipulate_resource_list(resources)
  resources + self.blog_data.tags.map do |tag, articles|
    path = TagPages.link(self.blog_options, tag)
    
    p = ::Middleman::Sitemap::Resource.new(
      @app.sitemap,
      path
    )
    p.proxy_to(self.blog_options.tag_template)

    # Add metadata in local variables so it's accessible to
    # later extensions
    p. :locals => {
      'page_type' => 'tag',
      'tagname' => tag,
      'articles' => articles,
      'blog_controller' => @blog_controller
    }
    # Add metadata in instance variables for backwards compatibility
    p. do
      @tag = tag
      @articles = articles
    end

    p
  end
end