Class: Middleman::Blog::CalendarPages
- Inherits:
-
Object
- Object
- Middleman::Blog::CalendarPages
- Includes:
- UriTemplates
- Defined in:
- lib/middleman-blog/calendar_pages.rb
Overview
A sitemap plugin that adds month/day/year pages to the sitemap based on the dates of blog articles.
Instance Method Summary collapse
-
#initialize(app, blog_controller) ⇒ CalendarPages
constructor
A new instance of CalendarPages.
-
#link(year, month = nil, day = nil) ⇒ String
Get a path to the given calendar page, based on the :year_link, :month_link or :day_link setting.
-
#manipulate_resource_list(resources) ⇒ Array<Middleman::Sitemap::Resource>
Update the main sitemap resource list.
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) ⇒ CalendarPages
Returns a new instance of CalendarPages.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/middleman-blog/calendar_pages.rb', line 12 def initialize(app, blog_controller) @sitemap = app.sitemap @blog_controller = blog_controller @blog_data = blog_controller.data = blog_controller. @day_link_template = uri_template .day_link @month_link_template = uri_template .month_link @year_link_template = uri_template .year_link @day_template = .day_template @month_template = .month_template @year_template = .year_template @generate_year_pages = .generate_year_pages @generate_month_pages = .generate_month_pages @generate_day_pages = .generate_day_pages end |
Instance Method Details
#link(year, month = nil, day = nil) ⇒ String
Get a path to the given calendar page, based on the :year_link, :month_link or :day_link setting.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/middleman-blog/calendar_pages.rb', line 34 def link(year, month = nil, day = nil) template = if day @day_link_template elsif month @month_link_template else @year_link_template end apply_uri_template template, date_to_params(Date.new(year, month || 1, day || 1)) end |
#manipulate_resource_list(resources) ⇒ Array<Middleman::Sitemap::Resource>
Update the main sitemap resource list
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/middleman-blog/calendar_pages.rb', line 48 def manipulate_resource_list(resources) new_resources = [] # Set up date pages if the appropriate templates have been specified @blog_data.articles.group_by { |a| a.date.year }.each do |year, year_articles| new_resources << year_page_resource(year, year_articles) if @generate_year_pages && @year_template year_articles.group_by { |a| a.date.month }.each do |month, month_articles| new_resources << month_page_resource(year, month, month_articles) if @generate_month_pages && @month_template month_articles.group_by { |a| a.date.day }.each do |day, day_articles| new_resources << day_page_resource(year, month, day, day_articles) if @generate_day_pages && @day_template end end end resources + new_resources end |