Class: Middleman::Blog::TagPages

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

Overview

A sitemap resource manipulator that adds a tag page to the sitemap for each tag in the associated blog

Instance Method Summary collapse

Methods included from UriTemplates

apply_uri_template, date_to_params, extract_directory_path, extract_params, safe_parameterize, uri_template

Constructor Details

#initialize(app, blog_controller) ⇒ TagPages

Initialise Tag pages

Parameters:

  • app (Object)

    Middleman app

  • blog_controller (Object)

    Blog controller



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

def initialize(app, blog_controller)
  @sitemap            = app.sitemap
  @blog_controller    = blog_controller
  @tag_link_template  = uri_template blog_controller.options.taglink
  @tag_template       = blog_controller.options.tag_template
  @blog_data          = blog_controller.data
  @generate_tag_pages = blog_controller.options.generate_tag_pages
end

Instance Method Details

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

Parameters:

  • tag (String)

    Tag name

Returns:

  • (String)

    Safe Tag URL



35
36
37
# File 'lib/middleman-blog/tag_pages.rb', line 35

def link(tag)
  apply_uri_template @tag_link_template, tag: safe_parameterize(tag)
end

#manipulate_resource_list(resources)

This method returns an undefined value.

Update the main sitemap resource list

Parameters:

  • resources (Object)

    Tag name



45
46
47
48
49
50
51
# File 'lib/middleman-blog/tag_pages.rb', line 45

def manipulate_resource_list(resources)
  return resources unless @generate_tag_pages

  resources + @blog_data.tags.map do |tag, articles|
    tag_page_resource(tag, articles)
  end
end