middleman-blog 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +25 -0
  3. data/.github/workflows/stale.yml +21 -0
  4. data/CHANGELOG.md +72 -60
  5. data/Gemfile +16 -26
  6. data/README.md +20 -36
  7. data/Rakefile +15 -19
  8. data/features/summary.feature +3 -6
  9. data/features/support/env.rb +9 -10
  10. data/features/support/time_steps.rb +13 -14
  11. data/features/tags.feature +5 -1
  12. data/fixtures/article-dirs-app/config-directory-indexes.rb +4 -2
  13. data/fixtures/article-dirs-app/config-permalink-with-dot.rb +4 -2
  14. data/fixtures/article-dirs-app/config.rb +4 -2
  15. data/fixtures/blog-sources-app/config.rb +3 -4
  16. data/fixtures/blog-sources-no-date-app/config.rb +3 -4
  17. data/fixtures/blog-sources-no-day-app/config.rb +3 -4
  18. data/fixtures/blog-sources-no-title-app/config.rb +2 -3
  19. data/fixtures/blog-sources-subdirs-app/config.rb +4 -5
  20. data/fixtures/calendar-and-tag-app/config-directory-indexes.rb +5 -3
  21. data/fixtures/calendar-and-tag-app/config.rb +6 -4
  22. data/fixtures/calendar-app/config-directory-indexes.rb +6 -6
  23. data/fixtures/calendar-app/config-only-year.rb +8 -8
  24. data/fixtures/calendar-app/config.rb +6 -6
  25. data/fixtures/calendar-multiblog-app/config.rb +14 -12
  26. data/fixtures/custom-article-template-app/config.rb +2 -0
  27. data/fixtures/custom-collections-app/config-blog-prefix.rb +9 -7
  28. data/fixtures/custom-collections-app/config-directory-indexes.rb +8 -6
  29. data/fixtures/custom-collections-app/config.rb +8 -6
  30. data/fixtures/custom-collections-multiblog-app/config.rb +16 -14
  31. data/fixtures/custom-collections-sources-app/config.rb +7 -5
  32. data/fixtures/custom-permalinks-app/config-directory-indexes.rb +5 -3
  33. data/fixtures/custom-permalinks-app/config.rb +5 -3
  34. data/fixtures/filename-date-app/config.rb +3 -1
  35. data/fixtures/future-date-app/config.rb +4 -2
  36. data/fixtures/indexes-app/config.rb +4 -2
  37. data/fixtures/lang-path-app/config.rb +4 -2
  38. data/fixtures/language-app/config.rb +3 -1
  39. data/fixtures/layouts-app/config.rb +3 -1
  40. data/fixtures/paginate-app/config-directory-indexes.rb +13 -13
  41. data/fixtures/paginate-app/config-paginate-off.rb +13 -13
  42. data/fixtures/paginate-app/config.rb +13 -13
  43. data/fixtures/paginate-multiblog-app/config.rb +15 -13
  44. data/fixtures/permalink-app/config.rb +4 -5
  45. data/fixtures/preview-app/config.rb +4 -2
  46. data/fixtures/published-app/config.rb +4 -2
  47. data/fixtures/summary-app/config.rb +2 -0
  48. data/fixtures/tags-app/config-directory-indexes.rb +7 -5
  49. data/fixtures/tags-app/config-filters.rb +2 -0
  50. data/fixtures/tags-app/config-no-tags.rb +2 -0
  51. data/fixtures/tags-app/config.rb +7 -5
  52. data/fixtures/tags-app/source/blog/2011-01-01-new-article.html.markdown +1 -1
  53. data/fixtures/tags-app/source/blog/2011-01-02-another-article.html.markdown +1 -0
  54. data/fixtures/tags-multiblog-app/config.rb +12 -10
  55. data/fixtures/time-zone-app/config.rb +2 -0
  56. data/lib/middleman-blog/blog_article.rb +20 -41
  57. data/lib/middleman-blog/blog_data.rb +22 -33
  58. data/lib/middleman-blog/calendar_pages.rb +16 -20
  59. data/lib/middleman-blog/commands/article.rb +54 -61
  60. data/lib/middleman-blog/commands/article.tt +2 -2
  61. data/lib/middleman-blog/custom_pages.rb +10 -9
  62. data/lib/middleman-blog/extension.rb +22 -19
  63. data/lib/middleman-blog/helpers.rb +18 -25
  64. data/lib/middleman-blog/paginator.rb +8 -5
  65. data/lib/middleman-blog/tag_pages.rb +13 -23
  66. data/lib/middleman-blog/truncate_html.rb +14 -11
  67. data/lib/middleman-blog/uri_templates.rb +37 -17
  68. data/lib/middleman-blog/version.rb +3 -3
  69. data/lib/middleman-blog.rb +7 -7
  70. data/lib/middleman_extension.rb +3 -1
  71. data/middleman-blog.gemspec +16 -23
  72. data/spec/spec_helper.rb +3 -4
  73. data/spec/uri_templates_spec.rb +24 -29
  74. metadata +15 -37
  75. data/.travis.yml +0 -38
  76. data/fixtures/default-template-app/Gemfile +0 -6
  77. data/fixtures/default-template-app/config.rb +0 -35
  78. data/fixtures/default-template-app/source/2013-04-01-new-article.html.markdown +0 -25
  79. data/fixtures/default-template-app/source/about-me.html.erb +0 -0
  80. data/fixtures/default-template-app/source/archives.html.erb +0 -10
  81. data/fixtures/default-template-app/source/index.html.erb +0 -11
  82. data/fixtures/default-template-app/source/javascripts/_zepto.pjax.js +0 -744
  83. data/fixtures/default-template-app/source/javascripts/app.js +0 -11
  84. data/fixtures/default-template-app/source/javascripts/modernizr.js +0 -1
  85. data/fixtures/default-template-app/source/layouts/layout.erb +0 -62
  86. data/fixtures/default-template-app/source/stylesheets/app.css.scss +0 -109
  87. /data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
  88. /data/{ISSUE_TEMPLATE.md → .github/ISSUE_TEMPLATE.md} +0 -0
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  activate :blog do |blog|
2
- blog.name = "blog_name_1"
3
- blog.prefix = "blog1"
4
- blog.sources = ":year-:month-:day-:title.html"
5
- blog.permalink = ":year-:month-:day-:title.html"
6
- blog.tag_template = "tag1.html"
4
+ blog.name = 'blog_name_1'
5
+ blog.prefix = 'blog1'
6
+ blog.sources = ':year-:month-:day-:title.html'
7
+ blog.permalink = ':year-:month-:day-:title.html'
8
+ blog.tag_template = 'tag1.html'
7
9
  end
8
10
 
9
11
  activate :blog do |blog|
10
- blog.name = "blog_name_2"
11
- blog.prefix = "blog2"
12
- blog.sources = ":year-:month-:day-:title.html"
13
- blog.permalink = ":year-:month-:day-:title.html"
14
- blog.tag_template = "tag2.html"
12
+ blog.name = 'blog_name_2'
13
+ blog.prefix = 'blog2'
14
+ blog.sources = ':year-:month-:day-:title.html'
15
+ blog.permalink = ':year-:month-:day-:title.html'
16
+ blog.tag_template = 'tag2.html'
15
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  set :time_zone, 'Tokyo'
2
4
 
3
5
  activate :blog do |blog|
@@ -1,12 +1,11 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'active_support/time_with_zone'
3
4
  require 'active_support/core_ext/time/acts_like'
4
5
  require 'active_support/core_ext/time/calculations'
5
6
 
6
7
  module Middleman
7
-
8
8
  module Blog
9
-
10
9
  ##
11
10
  # A module that adds blog-article-specific methods to Resources. A
12
11
  # {BlogArticle} can be retrieved via {Blog::Helpers#current_article} or
@@ -15,12 +14,8 @@ module Middleman
15
14
  # @see http://rdoc.info/github/middleman/middleman/Middleman/Sitemap/Resource Middleman::Sitemap::Resource
16
15
  ##
17
16
  module BlogArticle
18
-
19
17
  extend Gem::Deprecate
20
18
 
21
- ##
22
- #
23
- ##
24
19
  def self.extended(base)
25
20
  base.class.send(:attr_accessor, :blog_controller)
26
21
  end
@@ -49,9 +44,8 @@ module Middleman
49
44
  #
50
45
  # @return [String]
51
46
  ##
52
- def render(opts={}, locs={}, &block)
53
-
54
- unless opts.has_key?( :layout )
47
+ def render(opts = {}, locs = {}, &block)
48
+ unless opts.key?(:layout)
55
49
 
56
50
  opts[:layout] = metadata[:options][:layout]
57
51
  opts[:layout] = blog_options.layout if opts[:layout].nil? || opts[:layout] == :_auto_layout
@@ -63,9 +57,7 @@ module Middleman
63
57
 
64
58
  content = super(opts, locs, &block)
65
59
 
66
- unless opts[:keep_separator]
67
- content.sub!(blog_options.summary_separator, '')
68
- end
60
+ content.sub!(blog_options.summary_separator, '') unless opts[:keep_separator]
69
61
 
70
62
  content
71
63
  end
@@ -76,7 +68,7 @@ module Middleman
76
68
  # @return [String]
77
69
  ##
78
70
  def title
79
- data['title']
71
+ data['title'].to_s
80
72
  end
81
73
 
82
74
  ##
@@ -120,7 +112,7 @@ module Middleman
120
112
  # @param [String] ellipsis The ellipsis string to use when content is trimmed.
121
113
  # @return [String]
122
114
  ##
123
- def summary(length=nil, ellipsis='...')
115
+ def summary(length = nil, ellipsis = '...')
124
116
  rendered = render layout: false, keep_separator: true
125
117
 
126
118
  if blog_options.summary_generator
@@ -128,7 +120,6 @@ module Middleman
128
120
  else
129
121
  default_summary_generator(rendered, length, ellipsis)
130
122
  end
131
-
132
123
  end
133
124
 
134
125
  ##
@@ -142,7 +133,6 @@ module Middleman
142
133
  # @param [String] ellipsis The ellipsis string to use when content is trimmed.
143
134
  ##
144
135
  def default_summary_generator(rendered, length, ellipsis)
145
-
146
136
  if blog_options.summary_separator && rendered.match(blog_options.summary_separator)
147
137
  require 'middleman-blog/truncate_html'
148
138
  TruncateHTML.truncate_at_separator(rendered, blog_options.summary_separator)
@@ -151,14 +141,13 @@ module Middleman
151
141
  require 'middleman-blog/truncate_html'
152
142
  TruncateHTML.truncate_at_length(rendered, length, ellipsis)
153
143
 
154
- elsif blog_options.summary_length && blog_options.summary_length > 0
144
+ elsif blog_options.summary_length&.positive?
155
145
  require 'middleman-blog/truncate_html'
156
146
  TruncateHTML.truncate_at_length(rendered, blog_options.summary_length, ellipsis)
157
147
 
158
148
  else
159
149
  rendered
160
150
  end
161
-
162
151
  end
163
152
 
164
153
  ##
@@ -167,7 +156,6 @@ module Middleman
167
156
  # @return [Array<String>] (never +nil+)
168
157
  ##
169
158
  def tags
170
-
171
159
  article_tags = data['tags']
172
160
 
173
161
  if article_tags.is_a? String
@@ -175,7 +163,6 @@ module Middleman
175
163
  else
176
164
  Array(article_tags).map(&:to_s)
177
165
  end
178
-
179
166
  end
180
167
 
181
168
  ##
@@ -188,21 +175,18 @@ module Middleman
188
175
  # @return [Symbol] Language code (for example, +:en+ or +:de+)
189
176
  ##
190
177
  def locale
191
-
192
178
  frontmatter_locale = data['locale'] || data['lang']
193
179
  filename_locale = path_part('locale') || path_part('lang')
194
180
 
195
- if frontmatter_locale && filename_locale && frontmatter_locale != filename_locale
196
- raise "The locale in #{path}'s filename (#{filename_locale.inspect}) doesn't match the lang in its frontmatter (#{frontmatter_locale.inspect})"
197
- end
181
+ raise "The locale in #{path}'s filename (#{filename_locale.inspect}) doesn't match the lang in its frontmatter (#{frontmatter_locale.inspect})" if frontmatter_locale && filename_locale && frontmatter_locale != filename_locale
198
182
 
199
183
  default_locale = I18n.default_locale if defined? ::I18n
200
184
 
201
185
  found_locale = frontmatter_locale || filename_locale || default_locale
202
- found_locale && found_locale.to_sym
186
+ found_locale&.to_sym
203
187
  end
204
188
 
205
- alias_method :lang, :locale
189
+ alias lang locale
206
190
 
207
191
  ##
208
192
  # Attempt to figure out the date of the post. The date should be
@@ -213,16 +197,15 @@ module Middleman
213
197
  # @return [TimeWithZone]
214
198
  ##
215
199
  def date
216
-
217
200
  return @_date if @_date
218
201
 
219
202
  frontmatter_date = data['date']
220
203
 
221
204
  # First get the date from frontmatter
222
- if frontmatter_date.is_a? Time
223
- @_date = frontmatter_date.in_time_zone
205
+ @_date = if frontmatter_date.is_a? Time
206
+ frontmatter_date.in_time_zone
224
207
  else
225
- @_date = Time.zone.parse(frontmatter_date.to_s)
208
+ Time.zone.parse(frontmatter_date.to_s)
226
209
  end
227
210
 
228
211
  # Next figure out the date from the filename
@@ -244,7 +227,6 @@ module Middleman
244
227
  raise "Blog post #{path} needs a date in its filename or frontmatter" unless @_date
245
228
 
246
229
  @_date
247
-
248
230
  end
249
231
 
250
232
  ##
@@ -279,7 +261,7 @@ module Middleman
279
261
  # @return [BlogArticle]
280
262
  ##
281
263
  def previous_article
282
- article_previous()
264
+ article_previous
283
265
  end
284
266
  deprecate :previous_article, :article_previous, 2017, 5
285
267
 
@@ -292,7 +274,7 @@ module Middleman
292
274
  # @return [Middleman::Sitemap::Resource]
293
275
  ##
294
276
  def next_article
295
- article_next()
277
+ article_next
296
278
  end
297
279
  deprecate :next_article, :article_next, 2017, 5
298
280
 
@@ -303,7 +285,7 @@ module Middleman
303
285
  # @return [BlogArticle]
304
286
  ##
305
287
  def article_previous
306
- blog_data.articles.find { |a| a.date < self.date }
288
+ blog_data.articles.find { |a| a.date < date }
307
289
  end
308
290
 
309
291
  ##
@@ -313,7 +295,7 @@ module Middleman
313
295
  # @return [Middleman::Sitemap::Resource]
314
296
  ##
315
297
  def article_next
316
- blog_data.articles.reverse.find { |a| a.date > self.date }
298
+ blog_data.articles.reverse.find { |a| a.date > date }
317
299
  end
318
300
 
319
301
  ##
@@ -323,7 +305,7 @@ module Middleman
323
305
  # @return [BlogArticle]
324
306
  ##
325
307
  def article_locale_previous
326
- blog_data.local_articles.find { |a| a.date < self.date }
308
+ blog_data.local_articles.find { |a| a.date < date }
327
309
  end
328
310
 
329
311
  ##
@@ -333,7 +315,7 @@ module Middleman
333
315
  # @return [Middleman::Sitemap::Resource]
334
316
  ##
335
317
  def article_locale_next
336
- blog_data.local_articles.reverse.find { |a| a.date > self.date }
318
+ blog_data.local_articles.reverse.find { |a| a.date > date }
337
319
  end
338
320
 
339
321
  ##
@@ -357,9 +339,6 @@ module Middleman
357
339
  @_path_parts ||= Blog::UriTemplates.extract_params(blog_data.source_template, path)
358
340
  @_path_parts[part.to_s]
359
341
  end
360
-
361
342
  end
362
-
363
343
  end
364
-
365
344
  end
@@ -1,16 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'middleman-blog/uri_templates'
2
4
 
3
5
  module Middleman
4
-
5
6
  module Blog
6
-
7
7
  ##
8
8
  # A store of all the blog articles in the site, with accessors
9
9
  # for the articles by various dimensions. Accessed via "blog" in
10
10
  # templates.
11
11
  ##
12
12
  class BlogData
13
-
14
13
  include UriTemplates
15
14
  extend Gem::Deprecate
16
15
 
@@ -42,8 +41,8 @@ module Middleman
42
41
 
43
42
  @source_template = uri_template options.sources
44
43
  @permalink_template = uri_template options.permalink
45
- @subdir_template = uri_template options.sources.sub(/(\.[^.{}\/]+)?$/, "/{+path}" )
46
- @subdir_permalink_template = uri_template options.permalink.sub(/(\.[^.{}\/]+)?$/, "/{+path}" )
44
+ @subdir_template = uri_template options.sources.sub(/(\.[^.{}\/]+)?$/, '/{+path}')
45
+ @subdir_permalink_template = uri_template options.permalink.sub(/(\.[^.{}\/]+)?$/, '/{+path}')
47
46
  end
48
47
 
49
48
  ##
@@ -52,7 +51,7 @@ module Middleman
52
51
  # @return [Array<Middleman::Sitemap::Resource>]
53
52
  ##
54
53
  def articles
55
- @_articles.select( &( options.filter || proc { | a | a } ) ).sort_by( &:date ).reverse
54
+ @_articles.select(&options.filter || proc { |a| a }).sort_by(&:date).reverse
56
55
  end
57
56
 
58
57
  ##
@@ -64,8 +63,8 @@ module Middleman
64
63
  # @param [Symbol] locale Language to match (optional, defaults to I18n.locale).
65
64
  # @return [Array<Middleman::Sitemap::Resource>]
66
65
  ##
67
- def local_articles( locale = ::I18n.locale )
68
- articles_by_locale( locale )
66
+ def local_articles(locale = ::I18n.locale)
67
+ articles_by_locale(locale)
69
68
  end
70
69
  deprecate :local_articles, :articles_by_locale, 2017, 5
71
70
 
@@ -78,9 +77,9 @@ module Middleman
78
77
  #
79
78
  # @todo should use the @_articles if represented in this method.
80
79
  ##
81
- def articles_by_locale( locale = ::I18n.locale )
82
- locale = locale.to_sym if locale.kind_of? String
83
- articles.select { | article | article.locale == locale }
80
+ def articles_by_locale(locale = ::I18n.locale)
81
+ locale = locale.to_sym if locale.is_a? String
82
+ articles.select { |article| article.locale == locale }
84
83
  end
85
84
 
86
85
  ##
@@ -90,19 +89,16 @@ module Middleman
90
89
  # @return [Hash<String, Array<Middleman::Sitemap::Resource>>]
91
90
  ##
92
91
  def tags
93
-
94
92
  tags = {}
95
93
 
96
94
  # Reference the filtered articles
97
95
  articles.each do |article|
98
-
99
96
  # Reference the tags assigned to an article
100
97
  article.tags.each do |tag|
101
98
  # tag = safe_parameterize(tag)
102
99
  tags[tag] ||= []
103
100
  tags[tag] << article
104
101
  end
105
-
106
102
  end
107
103
 
108
104
  # Return tags
@@ -144,7 +140,7 @@ module Middleman
144
140
  next unless publishable?(article)
145
141
 
146
142
  # Add extra parameters from the URL to the page metadata
147
- extra_data = params.except *%w(year month day title lang locale)
143
+ extra_data = params.except 'year', 'month', 'day', 'title', 'lang', 'locale'
148
144
  article.add_metadata page: extra_data unless extra_data.empty?
149
145
 
150
146
  # compute output path: substitute date parts to path pattern
@@ -158,13 +154,13 @@ module Middleman
158
154
  # figure out the matching article for this subdirectory file
159
155
  article_path = @source_template.expand(params).to_s
160
156
 
161
- if article = @app.sitemap.find_resource_by_path(article_path)
157
+ if (article = @app.sitemap.find_resource_by_path(article_path))
162
158
  # The article may not yet have been processed, so convert it here.
163
159
  article = convert_to_article(article)
164
160
  next unless publishable?(article)
165
161
 
166
162
  # Add extra parameters from the URL to the page metadata
167
- extra_data = params.except *%w(year month day title lang locale)
163
+ extra_data = params.except 'year', 'month', 'day', 'title', 'lang', 'locale'
168
164
  article.add_metadata page: extra_data unless extra_data.empty?
169
165
 
170
166
  # The subdir path is the article path with the index file name
@@ -208,25 +204,22 @@ module Middleman
208
204
  # @param [Hash] extra More options to be merged in on top.
209
205
  # @return [Hash] options
210
206
  ##
211
- def permalink_options(resource, extra={})
207
+ def permalink_options(resource, extra = {})
212
208
  # Allow any frontmatter data to be substituted into the permalink URL
213
- params = resource.metadata[:page].slice *@permalink_template.variables.map(&:to_sym)
209
+ params = resource.metadata[:page].slice(*@permalink_template.variables.map(&:to_sym))
214
210
 
215
211
  params.each do |k, v|
216
212
  params[k] = safe_parameterize(v)
217
213
  end
218
214
 
219
- params.
220
- merge(date_to_params(resource.date)).
221
- merge(lang: resource.lang.to_s, locale: resource.locale.to_s, title: resource.slug).
222
- merge(extra)
215
+ params
216
+ .merge(date_to_params(resource.date))
217
+ .merge(lang: resource.lang.to_s, locale: resource.locale.to_s, title: resource.slug)
218
+ .merge(extra)
223
219
  end
224
220
 
225
- ##
226
- #
227
- ##
228
- def convert_to_article( resource )
229
- return resource if resource.is_a?( BlogArticle )
221
+ def convert_to_article(resource)
222
+ return resource if resource.is_a?(BlogArticle)
230
223
 
231
224
  resource.extend BlogArticle
232
225
  resource.blog_controller = controller
@@ -238,13 +231,9 @@ module Middleman
238
231
  resource
239
232
  end
240
233
 
241
- ##
242
- #
243
- ##
244
- def template_path(template, article, extras={})
234
+ def template_path(template, article, extras = {})
245
235
  apply_uri_template template, permalink_options(article, extras)
246
236
  end
247
-
248
237
  end
249
238
  end
250
239
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'middleman-blog/uri_templates'
2
4
 
3
5
  module Middleman
@@ -29,14 +31,14 @@ module Middleman
29
31
  # @param [Number] month
30
32
  # @param [Number] day
31
33
  # @return [String]
32
- def link(year, month=nil, day=nil)
34
+ def link(year, month = nil, day = nil)
33
35
  template = if day
34
- @day_link_template
35
- elsif month
36
- @month_link_template
37
- else
38
- @year_link_template
39
- end
36
+ @day_link_template
37
+ elsif month
38
+ @month_link_template
39
+ else
40
+ @year_link_template
41
+ end
40
42
 
41
43
  apply_uri_template template, date_to_params(Date.new(year, month || 1, day || 1))
42
44
  end
@@ -47,20 +49,14 @@ module Middleman
47
49
  new_resources = []
48
50
 
49
51
  # Set up date pages if the appropriate templates have been specified
50
- @blog_data.articles.group_by {|a| a.date.year }.each do |year, year_articles|
51
- if @generate_year_pages && @year_template
52
- new_resources << year_page_resource(year, year_articles)
53
- end
52
+ @blog_data.articles.group_by { |a| a.date.year }.each do |year, year_articles|
53
+ new_resources << year_page_resource(year, year_articles) if @generate_year_pages && @year_template
54
54
 
55
- year_articles.group_by {|a| a.date.month }.each do |month, month_articles|
56
- if @generate_month_pages && @month_template
57
- new_resources << month_page_resource(year, month, month_articles)
58
- end
55
+ year_articles.group_by { |a| a.date.month }.each do |month, month_articles|
56
+ new_resources << month_page_resource(year, month, month_articles) if @generate_month_pages && @month_template
59
57
 
60
- month_articles.group_by {|a| a.date.day }.each do |day, day_articles|
61
- if @generate_day_pages && @day_template
62
- new_resources << day_page_resource(year, month, day, day_articles)
63
- end
58
+ month_articles.group_by { |a| a.date.day }.each do |day, day_articles|
59
+ new_resources << day_page_resource(year, month, day, day_articles) if @generate_day_pages && @day_template
64
60
  end
65
61
  end
66
62
  end
@@ -109,4 +105,4 @@ module Middleman
109
105
  end
110
106
  end
111
107
  end
112
- end
108
+ end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'middleman-core/cli'
2
4
  require 'date'
3
5
  require 'middleman-blog/uri_templates'
4
6
 
5
7
  module Middleman
6
-
7
8
  module Cli
8
-
9
9
  ##
10
10
  # This class provides an "article" command for the middleman CLI.
11
11
  #
@@ -18,7 +18,6 @@ module Middleman
18
18
  # @todo Tags should be removed from the template if they are not required
19
19
  ##
20
20
  class Article < ::Thor::Group
21
-
22
21
  include Thor::Actions
23
22
  include Blog::UriTemplates
24
23
 
@@ -27,110 +26,104 @@ module Middleman
27
26
  # Template files are relative to this file
28
27
  # @return [String]
29
28
  def self.source_root
30
- File.dirname( __FILE__ )
29
+ File.dirname(__FILE__)
31
30
  end
32
31
 
33
32
  argument :title, type: :string
34
33
 
35
- class_option "blog",
36
- aliases: "-b",
37
- desc: "The name of the blog to create the post inside (for multi-blog apps, defaults to the only blog in single-blog apps)"
34
+ class_option 'blog',
35
+ aliases: '-b',
36
+ desc: 'The name of the blog to create the post inside (for multi-blog apps, defaults to the only blog in single-blog apps)'
38
37
 
39
- class_option "content",
40
- aliases: "-c",
41
- desc: "Content of the post"
38
+ class_option 'content',
39
+ aliases: '-c',
40
+ desc: 'Content of the post'
42
41
 
43
- class_option "date",
44
- aliases: "-d",
45
- desc: "The date to create the post with (defaults to now)"
42
+ class_option 'date',
43
+ aliases: '-d',
44
+ desc: 'The date to create the post with (defaults to now)'
46
45
 
47
- class_option "locale",
48
- aliases: "-l",
49
- desc: "The locale to create the post with (defaults to I18n.default_locale if available)"
46
+ class_option 'locale',
47
+ aliases: '-l',
48
+ desc: 'The locale to create the post with (defaults to I18n.default_locale if available)'
50
49
 
51
- class_option "edit",
52
- aliases: "-e",
53
- desc: "Edit the newly created blog post",
54
- default: false,
55
- type: :boolean
50
+ class_option 'edit',
51
+ aliases: '-e',
52
+ desc: 'Edit the newly created blog post',
53
+ default: false,
54
+ type: :boolean
56
55
 
57
- class_option "subdirectory",
58
- aliases: "-s",
59
- desc: "Generate an article subdirectory (for directory indexes, defaults to false)",
60
- default: false,
61
- type: :boolean
56
+ class_option 'subdirectory',
57
+ aliases: '-s',
58
+ desc: 'Generate an article subdirectory (for directory indexes, defaults to false)',
59
+ default: false,
60
+ type: :boolean
62
61
 
63
- class_option "tags",
64
- aliases: "-t",
65
- desc: "A list of comma-separated tags for the post"
62
+ class_option 'tags',
63
+ aliases: '-t',
64
+ desc: 'A list of comma-separated tags for the post'
66
65
 
67
66
  def article
68
-
69
- @content = options[:content] || ""
70
- @date = options[ :date ] ? ::Time.zone.parse( options[ :date ] ) : Time.zone.now
71
- @locale = options[ :locale ] || ( ::I18n.default_locale if defined? ::I18n )
72
- @slug = safe_parameterize( title )
73
- @tags = options[:tags] && options[:tags].split(/\s*,\s*/) || []
67
+ @content = options[:content] || ''
68
+ @date = options[:date] ? ::Time.zone.parse(options[:date]) : Time.zone.now
69
+ @locale = options[:locale] || (::I18n.default_locale if defined? ::I18n)
70
+ @slug = safe_parameterize(title)
71
+ @tags = options[:tags]&.split(/\s*,\s*/) || []
74
72
  @title = title
75
73
 
76
74
  app = ::Middleman::Application.new do
77
- config[ :mode ] = :config
78
- config[ :disable_sitemap ] = true
79
- config[ :watcher_disable ] = true
80
- config[ :exit_before_ready ] = true
75
+ config[:mode] = :config
76
+ config[:disable_sitemap] = true
77
+ config[:watcher_disable] = true
78
+ config[:exit_before_ready] = true
81
79
  end
82
80
 
83
- blog_inst = if options[ :blog ]
84
- app.extensions[ :blog ].find { | key, instance | instance.options[ :name ] == options[ :blog ] }[ 1 ]
81
+ blog_inst = if options[:blog]
82
+ app.extensions[:blog].find { |_key, instance| instance.options[:name] == options[:blog] }[ 1 ]
85
83
  else
86
- app.extensions[ :blog ].values.first
84
+ app.extensions[:blog].values.first
87
85
  end
88
86
 
89
87
  unless blog_inst
90
- msg = "Could not find an active blog instance"
91
- msg << " named #{ options[ :blog ] }" if options[ :blog ]
88
+ msg = 'Could not find an active blog instance'
89
+ msg = "#{msg} named #{options[:blog]}" if options[:blog]
92
90
  throw msg
93
91
  end
94
92
 
95
93
  path_template = blog_inst.data.source_template
96
- params = date_to_params( @date ).merge( locale: @locale.to_s, title: @slug )
94
+ params = date_to_params(@date).merge(locale: @locale.to_s, title: @slug)
97
95
  article_path = apply_uri_template path_template, params
98
- absolute_article_path = File.join( app.source_dir, article_path + blog_inst.options.default_extension )
96
+ absolute_article_path = File.join(app.source_dir, article_path + blog_inst.options.default_extension)
99
97
 
100
98
  template blog_inst.options.new_article_template, absolute_article_path
101
99
 
102
100
  # Edit option process
103
- if options[ :edit ]
101
+ if options[:edit]
104
102
 
105
- editor = ENV.fetch( 'MM_EDITOR', ENV.fetch( 'EDITOR', nil ) )
103
+ editor = ENV.fetch('MM_EDITOR', ENV.fetch('EDITOR', nil))
106
104
 
107
105
  if editor
108
- system( "#{ editor } #{ absolute_article_path }" )
106
+ system("#{editor} #{absolute_article_path}")
109
107
  else
110
- throw "Could not find a suitable editor. Try setting the environment variable MM_EDITOR."
108
+ throw 'Could not find a suitable editor. Try setting the environment variable MM_EDITOR.'
111
109
  end
112
110
 
113
111
  end
114
112
 
115
113
  # Subdirectory option process
116
- if options[ :subdirectory ]
117
- empty_directory extract_directory_path( File.join( app.source_dir, article_path ) )
118
- end
119
-
114
+ empty_directory extract_directory_path(File.join(app.source_dir, article_path)) if options[:subdirectory]
120
115
  end
121
116
 
122
117
  protected
123
118
 
124
- def blog_instance( key )
125
- return nil unless app.extensions[ :blog ]
126
- return app.extensions[ :blog ][ key ]
119
+ def blog_instance(key)
120
+ return nil unless app.extensions[:blog]
121
+
122
+ app.extensions[:blog][key]
127
123
  end
128
124
 
129
125
  # Add to CLI
130
- Base.register( self, 'article', 'article TITLE [options]', 'Create a new blog article' )
131
-
126
+ Base.register(self, 'article', 'article TITLE [options]', 'Create a new blog article')
132
127
  end
133
-
134
128
  end
135
-
136
129
  end
@@ -1,7 +1,7 @@
1
1
  ---
2
2
 
3
- title: <%= @title %>
4
- date: <%= @date.strftime('%F %R %Z') %>
3
+ title: "<%= %Q[#{@title}] %>"
4
+ date: <%= @date.strftime('%F %R %z') %>
5
5
  tags: <%= @tags.join(",") %>
6
6
 
7
7
  ---