Class: Middleman::Blog::CalendarPages
- Inherits:
-
Object
- Object
- Middleman::Blog::CalendarPages
- 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.
Class Method Summary collapse
-
.link(blog_options, 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.
Instance Method Summary collapse
- #blog_data ⇒ Object
- #blog_options ⇒ Object
-
#initialize(app, controller = nil) ⇒ CalendarPages
constructor
A new instance of CalendarPages.
-
#manipulate_resource_list(resources)
Update the main sitemap resource list.
Constructor Details
#initialize(app, controller = nil) ⇒ CalendarPages
Returns a new instance of CalendarPages.
32 33 34 35 |
# File 'lib/middleman-blog/calendar_pages.rb', line 32 def initialize(app, controller=nil) @app = app @blog_controller = controller end |
Class Method Details
.link(blog_options, 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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/middleman-blog/calendar_pages.rb', line 14 def link(, year, month=nil, day=nil) path = if day .day_link. sub(':year', year.to_s). sub(':month', month.to_s.rjust(2,'0')). sub(':day', day.to_s.rjust(2,'0')) elsif month .month_link. sub(':year', year.to_s). sub(':month', month.to_s.rjust(2,'0')) else .year_link. sub(':year', year.to_s) end ::Middleman::Util.normalize_path(path) end |
Instance Method Details
#blog_data ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/middleman-blog/calendar_pages.rb', line 37 def blog_data if @blog_controller @blog_controller.data else @app.blog end end |
#blog_options ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/middleman-blog/calendar_pages.rb', line 45 def if @blog_controller @blog_controller. else @app.blog. end end |
#manipulate_resource_list(resources)
This method returns an undefined value.
Update the main sitemap resource list
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/middleman-blog/calendar_pages.rb', line 55 def manipulate_resource_list(resources) new_resources = [] # Set up date pages if the appropriate templates have been specified self.blog_data.articles.group_by {|a| a.date.year }.each do |year, year_articles| if self..year_template path = CalendarPages.link(self., year) p = ::Middleman::Sitemap::Resource.new( @app.sitemap, path ) p.proxy_to(self..year_template) # Add metadata in local variables so it's accessible to # later extensions p. :locals => { 'page_type' => 'year', 'year' => year, 'articles' => year_articles, 'blog_controller' => @blog_controller } # Add metadata in instance variables for backwards compatibility p. do @year = year @articles = year_articles end new_resources << p end year_articles.group_by {|a| a.date.month }.each do |month, month_articles| if self..month_template path = CalendarPages.link(self., year, month) p = ::Middleman::Sitemap::Resource.new( @app.sitemap, path ) p.proxy_to(self..month_template) p. :locals => { 'page_type' => 'month', 'year' => year, 'month' => month, 'articles' => month_articles, 'blog_controller' => @blog_controller } p. do @year = year @month = month @articles = month_articles end new_resources << p end month_articles.group_by {|a| a.date.day }.each do |day, day_articles| if self..day_template path = CalendarPages.link(self., year, month, day) p = ::Middleman::Sitemap::Resource.new( @app.sitemap, path ) p.proxy_to(self..day_template) p. :locals => { 'page_type' => 'day', 'year' => year, 'month' => month, 'day' => day, 'articles' => day_articles, 'blog_controller' => @blog_controller } p. do @year = year @month = month @day = day @articles = day_articles end new_resources << p end end end end resources + new_resources end |