middleman-blog 4.0.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +69 -0
- data/.travis.yml +20 -28
- data/CHANGELOG.md +4 -4
- data/Gemfile +20 -21
- data/Gemfile-4.x +38 -0
- data/README.md +0 -6
- data/Rakefile +14 -12
- data/features/summary.feature +3 -6
- data/features/support/env.rb +7 -10
- data/features/support/time_steps.rb +7 -10
- data/features/tags.feature +1 -1
- data/fixtures/article-dirs-app/config-directory-indexes.rb +2 -2
- data/fixtures/article-dirs-app/config-permalink-with-dot.rb +2 -2
- data/fixtures/article-dirs-app/config.rb +2 -2
- data/fixtures/blog-sources-app/config.rb +2 -5
- data/fixtures/blog-sources-no-date-app/config.rb +2 -5
- data/fixtures/blog-sources-no-day-app/config.rb +2 -5
- data/fixtures/blog-sources-no-title-app/config.rb +1 -4
- data/fixtures/blog-sources-subdirs-app/config.rb +3 -6
- data/fixtures/calendar-and-tag-app/config-directory-indexes.rb +3 -3
- data/fixtures/calendar-and-tag-app/config.rb +4 -4
- data/fixtures/calendar-app/config-directory-indexes.rb +5 -7
- data/fixtures/calendar-app/config-only-year.rb +7 -9
- data/fixtures/calendar-app/config.rb +5 -7
- data/fixtures/calendar-multiblog-app/config.rb +12 -12
- data/fixtures/custom-collections-app/config-blog-prefix.rb +7 -7
- data/fixtures/custom-collections-app/config-directory-indexes.rb +6 -6
- data/fixtures/custom-collections-app/config.rb +6 -6
- data/fixtures/custom-collections-multiblog-app/config.rb +14 -14
- data/fixtures/custom-collections-sources-app/config.rb +5 -5
- data/fixtures/custom-permalinks-app/config-directory-indexes.rb +3 -3
- data/fixtures/custom-permalinks-app/config.rb +3 -3
- data/fixtures/default-template-app/Gemfile +5 -5
- data/fixtures/default-template-app/config.rb +11 -11
- data/fixtures/filename-date-app/config.rb +1 -1
- data/fixtures/future-date-app/config.rb +2 -2
- data/fixtures/indexes-app/config.rb +2 -2
- data/fixtures/lang-path-app/config.rb +2 -2
- data/fixtures/layouts-app/config.rb +1 -1
- data/fixtures/paginate-app/config-directory-indexes.rb +12 -14
- data/fixtures/paginate-app/config-paginate-off.rb +12 -14
- data/fixtures/paginate-app/config.rb +12 -14
- data/fixtures/paginate-multiblog-app/config.rb +13 -13
- data/fixtures/permalink-app/config.rb +3 -6
- data/fixtures/preview-app/config.rb +2 -2
- data/fixtures/published-app/config.rb +2 -2
- data/fixtures/tags-app/config-directory-indexes.rb +5 -5
- data/fixtures/tags-app/config.rb +5 -5
- data/fixtures/tags-multiblog-app/config.rb +10 -10
- data/lib/middleman-blog.rb +6 -8
- data/lib/middleman-blog/blog_article.rb +20 -40
- data/lib/middleman-blog/blog_data.rb +20 -27
- data/lib/middleman-blog/calendar_pages.rb +8 -14
- data/lib/middleman-blog/commands/article.rb +54 -63
- data/lib/middleman-blog/custom_pages.rb +8 -9
- data/lib/middleman-blog/extension.rb +7 -8
- data/lib/middleman-blog/helpers.rb +17 -26
- data/lib/middleman-blog/paginator.rb +5 -4
- data/lib/middleman-blog/tag_pages.rb +11 -23
- data/lib/middleman-blog/truncate_html.rb +8 -7
- data/lib/middleman-blog/uri_templates.rb +31 -17
- data/lib/middleman-blog/version.rb +1 -3
- data/lib/middleman_extension.rb +1 -1
- data/middleman-blog.gemspec +15 -15
- data/spec/spec_helper.rb +1 -4
- data/spec/uri_templates_spec.rb +23 -30
- metadata +10 -9
@@ -1,18 +1,16 @@
|
|
1
|
-
activate :blog do |
|
1
|
+
activate :blog do |blog|
|
2
|
+
blog.sources = 'blog/:year-:month-:day-:title.html'
|
3
|
+
blog.permalink = 'blog/:year-:month-:day-:title.html'
|
4
|
+
blog.calendar_template = 'calendar.html'
|
5
|
+
blog.tag_template = 'tag.html'
|
6
|
+
blog.paginate = true
|
7
|
+
blog.per_page = 5
|
2
8
|
|
3
|
-
|
4
|
-
blog.permalink = "blog/:year-:month-:day-:title.html"
|
5
|
-
blog.calendar_template = 'calendar.html'
|
6
|
-
blog.tag_template = 'tag.html'
|
7
|
-
blog.paginate = true
|
8
|
-
blog.per_page = 5
|
9
|
+
blog.custom_collections = {
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:link => '/categories/:category.html',
|
14
|
-
:template => '/category.html'
|
15
|
-
}
|
11
|
+
category: {
|
12
|
+
link: '/categories/:category.html',
|
13
|
+
template: '/category.html'
|
16
14
|
}
|
17
|
-
|
15
|
+
}
|
18
16
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
activate :blog do |blog|
|
2
|
-
blog.name =
|
3
|
-
blog.prefix =
|
4
|
-
blog.sources =
|
5
|
-
blog.permalink =
|
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
6
|
blog.calendar_template = 'calendar1.html'
|
7
7
|
blog.tag_template = 'tag1.html'
|
8
8
|
blog.paginate = true
|
@@ -10,10 +10,10 @@ activate :blog do |blog|
|
|
10
10
|
end
|
11
11
|
|
12
12
|
activate :blog do |blog2|
|
13
|
-
blog2.name =
|
14
|
-
blog2.prefix =
|
15
|
-
blog2.sources =
|
16
|
-
blog2.permalink =
|
13
|
+
blog2.name = 'blog_name_2'
|
14
|
+
blog2.prefix = 'blog2'
|
15
|
+
blog2.sources = ':year-:month-:day-:title.html'
|
16
|
+
blog2.permalink = ':year-:month-:day-:title.html'
|
17
17
|
blog2.calendar_template = 'calendar2.html'
|
18
18
|
blog2.tag_template = 'tag2.html'
|
19
19
|
blog2.paginate = true
|
@@ -21,11 +21,11 @@ activate :blog do |blog2|
|
|
21
21
|
end
|
22
22
|
|
23
23
|
activate :blog do |blog3|
|
24
|
-
blog3.name =
|
25
|
-
blog3.prefix =
|
26
|
-
blog3.sources =
|
27
|
-
blog3.permalink =
|
24
|
+
blog3.name = 'blog_name_3'
|
25
|
+
blog3.prefix = 'blog3'
|
26
|
+
blog3.sources = ':year-:month-:day-:title.html'
|
27
|
+
blog3.permalink = ':year-:month-:day-:title.html'
|
28
28
|
blog3.calendar_template = 'calendar3.html'
|
29
29
|
blog3.tag_template = 'tag3.html'
|
30
30
|
blog3.paginate = false
|
31
|
-
end
|
31
|
+
end
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
blog.sources = ":category/:year-:month-:day-:title.html"
|
5
|
-
blog.permalink = ":category/:custom-:year-:month-:day-:title.html"
|
6
|
-
|
1
|
+
activate :blog do |blog|
|
2
|
+
blog.sources = ':category/:year-:month-:day-:title.html'
|
3
|
+
blog.permalink = ':category/:custom-:year-:month-:day-:title.html'
|
7
4
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
activate :blog do |blog|
|
2
|
-
blog.sources =
|
3
|
-
end
|
2
|
+
blog.sources = ':year/:month/:day/:title.html'
|
3
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
activate :blog do |blog|
|
2
|
-
blog.sources =
|
3
|
-
end
|
2
|
+
blog.sources = 'blog/:year-:month-:day-:title.html'
|
3
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'middleman-blog'
|
2
2
|
|
3
|
-
activate :blog do |
|
4
|
-
blog.sources =
|
5
|
-
blog.permalink =
|
6
|
-
blog.tag_template =
|
3
|
+
activate :blog do |blog|
|
4
|
+
blog.sources = 'blog/:year-:month-:day-:title.html'
|
5
|
+
blog.permalink = 'blog/:year-:month-:day-:title.html'
|
6
|
+
blog.tag_template = '/tag.html'
|
7
7
|
end
|
8
8
|
|
9
9
|
activate :directory_indexes
|
data/fixtures/tags-app/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'middleman-blog'
|
2
2
|
|
3
|
-
activate :blog do |
|
4
|
-
blog.sources =
|
5
|
-
blog.permalink =
|
6
|
-
blog.tag_template =
|
3
|
+
activate :blog do |blog|
|
4
|
+
blog.sources = 'blog/:year-:month-:day-:title.html'
|
5
|
+
blog.permalink = 'blog/:year-:month-:day-:title.html'
|
6
|
+
blog.tag_template = '/tag.html'
|
7
7
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
activate :blog do |blog|
|
2
|
-
blog.name =
|
3
|
-
blog.prefix =
|
4
|
-
blog.sources =
|
5
|
-
blog.permalink =
|
6
|
-
blog.tag_template =
|
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'
|
7
7
|
end
|
8
8
|
|
9
9
|
activate :blog do |blog|
|
10
|
-
blog.name =
|
11
|
-
blog.prefix =
|
12
|
-
blog.sources =
|
13
|
-
blog.permalink =
|
14
|
-
blog.tag_template =
|
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'
|
15
15
|
end
|
data/lib/middleman-blog.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'middleman-core'
|
2
|
+
require 'middleman-blog/version'
|
3
3
|
|
4
|
-
::Middleman::Extensions.register(
|
5
|
-
|
6
|
-
|
7
|
-
require "middleman-blog/commands/article"
|
8
|
-
|
9
|
-
::Middleman::BlogExtension
|
4
|
+
::Middleman::Extensions.register(:blog) do
|
5
|
+
require 'middleman-blog/extension'
|
6
|
+
require 'middleman-blog/commands/article'
|
10
7
|
|
8
|
+
::Middleman::BlogExtension
|
11
9
|
end
|
@@ -1,12 +1,9 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'active_support/time_with_zone'
|
3
2
|
require 'active_support/core_ext/time/acts_like'
|
4
3
|
require 'active_support/core_ext/time/calculations'
|
5
4
|
|
6
5
|
module Middleman
|
7
|
-
|
8
6
|
module Blog
|
9
|
-
|
10
7
|
##
|
11
8
|
# A module that adds blog-article-specific methods to Resources. A
|
12
9
|
# {BlogArticle} can be retrieved via {Blog::Helpers#current_article} or
|
@@ -15,7 +12,6 @@ module Middleman
|
|
15
12
|
# @see http://rdoc.info/github/middleman/middleman/Middleman/Sitemap/Resource Middleman::Sitemap::Resource
|
16
13
|
##
|
17
14
|
module BlogArticle
|
18
|
-
|
19
15
|
extend Gem::Deprecate
|
20
16
|
|
21
17
|
##
|
@@ -49,9 +45,8 @@ module Middleman
|
|
49
45
|
#
|
50
46
|
# @return [String]
|
51
47
|
##
|
52
|
-
def render(opts={}, locs={}, &block)
|
53
|
-
|
54
|
-
unless opts.has_key?( :layout )
|
48
|
+
def render(opts = {}, locs = {}, &block)
|
49
|
+
unless opts.key?(:layout)
|
55
50
|
|
56
51
|
opts[:layout] = metadata[:options][:layout]
|
57
52
|
opts[:layout] = blog_options.layout if opts[:layout].nil? || opts[:layout] == :_auto_layout
|
@@ -63,9 +58,7 @@ module Middleman
|
|
63
58
|
|
64
59
|
content = super(opts, locs, &block)
|
65
60
|
|
66
|
-
unless opts[:keep_separator]
|
67
|
-
content.sub!(blog_options.summary_separator, '')
|
68
|
-
end
|
61
|
+
content.sub!(blog_options.summary_separator, '') unless opts[:keep_separator]
|
69
62
|
|
70
63
|
content
|
71
64
|
end
|
@@ -76,7 +69,7 @@ module Middleman
|
|
76
69
|
# @return [String]
|
77
70
|
##
|
78
71
|
def title
|
79
|
-
data['title']
|
72
|
+
data['title'].to_s
|
80
73
|
end
|
81
74
|
|
82
75
|
##
|
@@ -120,7 +113,7 @@ module Middleman
|
|
120
113
|
# @param [String] ellipsis The ellipsis string to use when content is trimmed.
|
121
114
|
# @return [String]
|
122
115
|
##
|
123
|
-
def summary(length=nil, ellipsis='...')
|
116
|
+
def summary(length = nil, ellipsis = '...')
|
124
117
|
rendered = render layout: false, keep_separator: true
|
125
118
|
|
126
119
|
if blog_options.summary_generator
|
@@ -128,7 +121,6 @@ module Middleman
|
|
128
121
|
else
|
129
122
|
default_summary_generator(rendered, length, ellipsis)
|
130
123
|
end
|
131
|
-
|
132
124
|
end
|
133
125
|
|
134
126
|
##
|
@@ -142,7 +134,6 @@ module Middleman
|
|
142
134
|
# @param [String] ellipsis The ellipsis string to use when content is trimmed.
|
143
135
|
##
|
144
136
|
def default_summary_generator(rendered, length, ellipsis)
|
145
|
-
|
146
137
|
if blog_options.summary_separator && rendered.match(blog_options.summary_separator)
|
147
138
|
require 'middleman-blog/truncate_html'
|
148
139
|
TruncateHTML.truncate_at_separator(rendered, blog_options.summary_separator)
|
@@ -151,14 +142,13 @@ module Middleman
|
|
151
142
|
require 'middleman-blog/truncate_html'
|
152
143
|
TruncateHTML.truncate_at_length(rendered, length, ellipsis)
|
153
144
|
|
154
|
-
elsif blog_options.summary_length
|
145
|
+
elsif blog_options.summary_length&.positive?
|
155
146
|
require 'middleman-blog/truncate_html'
|
156
147
|
TruncateHTML.truncate_at_length(rendered, blog_options.summary_length, ellipsis)
|
157
148
|
|
158
149
|
else
|
159
150
|
rendered
|
160
151
|
end
|
161
|
-
|
162
152
|
end
|
163
153
|
|
164
154
|
##
|
@@ -167,7 +157,6 @@ module Middleman
|
|
167
157
|
# @return [Array<String>] (never +nil+)
|
168
158
|
##
|
169
159
|
def tags
|
170
|
-
|
171
160
|
article_tags = data['tags']
|
172
161
|
|
173
162
|
if article_tags.is_a? String
|
@@ -175,7 +164,6 @@ module Middleman
|
|
175
164
|
else
|
176
165
|
Array(article_tags).map(&:to_s)
|
177
166
|
end
|
178
|
-
|
179
167
|
end
|
180
168
|
|
181
169
|
##
|
@@ -188,21 +176,18 @@ module Middleman
|
|
188
176
|
# @return [Symbol] Language code (for example, +:en+ or +:de+)
|
189
177
|
##
|
190
178
|
def locale
|
191
|
-
|
192
179
|
frontmatter_locale = data['locale'] || data['lang']
|
193
180
|
filename_locale = path_part('locale') || path_part('lang')
|
194
181
|
|
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
|
182
|
+
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
183
|
|
199
184
|
default_locale = I18n.default_locale if defined? ::I18n
|
200
185
|
|
201
186
|
found_locale = frontmatter_locale || filename_locale || default_locale
|
202
|
-
found_locale
|
187
|
+
found_locale&.to_sym
|
203
188
|
end
|
204
189
|
|
205
|
-
|
190
|
+
alias lang locale
|
206
191
|
|
207
192
|
##
|
208
193
|
# Attempt to figure out the date of the post. The date should be
|
@@ -213,17 +198,16 @@ module Middleman
|
|
213
198
|
# @return [TimeWithZone]
|
214
199
|
##
|
215
200
|
def date
|
216
|
-
|
217
201
|
return @_date if @_date
|
218
202
|
|
219
203
|
frontmatter_date = data['date']
|
220
204
|
|
221
205
|
# First get the date from frontmatter
|
222
|
-
if frontmatter_date.is_a? Time
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
206
|
+
@_date = if frontmatter_date.is_a? Time
|
207
|
+
frontmatter_date.in_time_zone
|
208
|
+
else
|
209
|
+
Time.zone.parse(frontmatter_date.to_s)
|
210
|
+
end
|
227
211
|
|
228
212
|
# Next figure out the date from the filename
|
229
213
|
source_vars = blog_data.source_template.variables
|
@@ -244,7 +228,6 @@ module Middleman
|
|
244
228
|
raise "Blog post #{path} needs a date in its filename or frontmatter" unless @_date
|
245
229
|
|
246
230
|
@_date
|
247
|
-
|
248
231
|
end
|
249
232
|
|
250
233
|
##
|
@@ -279,7 +262,7 @@ module Middleman
|
|
279
262
|
# @return [BlogArticle]
|
280
263
|
##
|
281
264
|
def previous_article
|
282
|
-
article_previous
|
265
|
+
article_previous
|
283
266
|
end
|
284
267
|
deprecate :previous_article, :article_previous, 2017, 5
|
285
268
|
|
@@ -292,7 +275,7 @@ module Middleman
|
|
292
275
|
# @return [Middleman::Sitemap::Resource]
|
293
276
|
##
|
294
277
|
def next_article
|
295
|
-
article_next
|
278
|
+
article_next
|
296
279
|
end
|
297
280
|
deprecate :next_article, :article_next, 2017, 5
|
298
281
|
|
@@ -303,7 +286,7 @@ module Middleman
|
|
303
286
|
# @return [BlogArticle]
|
304
287
|
##
|
305
288
|
def article_previous
|
306
|
-
blog_data.articles.find { |a| a.date <
|
289
|
+
blog_data.articles.find { |a| a.date < date }
|
307
290
|
end
|
308
291
|
|
309
292
|
##
|
@@ -313,7 +296,7 @@ module Middleman
|
|
313
296
|
# @return [Middleman::Sitemap::Resource]
|
314
297
|
##
|
315
298
|
def article_next
|
316
|
-
blog_data.articles.reverse.find { |a| a.date >
|
299
|
+
blog_data.articles.reverse.find { |a| a.date > date }
|
317
300
|
end
|
318
301
|
|
319
302
|
##
|
@@ -323,7 +306,7 @@ module Middleman
|
|
323
306
|
# @return [BlogArticle]
|
324
307
|
##
|
325
308
|
def article_locale_previous
|
326
|
-
blog_data.local_articles.find { |a| a.date <
|
309
|
+
blog_data.local_articles.find { |a| a.date < date }
|
327
310
|
end
|
328
311
|
|
329
312
|
##
|
@@ -333,7 +316,7 @@ module Middleman
|
|
333
316
|
# @return [Middleman::Sitemap::Resource]
|
334
317
|
##
|
335
318
|
def article_locale_next
|
336
|
-
blog_data.local_articles.reverse.find { |a| a.date >
|
319
|
+
blog_data.local_articles.reverse.find { |a| a.date > date }
|
337
320
|
end
|
338
321
|
|
339
322
|
##
|
@@ -357,9 +340,6 @@ module Middleman
|
|
357
340
|
@_path_parts ||= Blog::UriTemplates.extract_params(blog_data.source_template, path)
|
358
341
|
@_path_parts[part.to_s]
|
359
342
|
end
|
360
|
-
|
361
343
|
end
|
362
|
-
|
363
344
|
end
|
364
|
-
|
365
345
|
end
|
@@ -1,16 +1,13 @@
|
|
1
1
|
require 'middleman-blog/uri_templates'
|
2
2
|
|
3
3
|
module Middleman
|
4
|
-
|
5
4
|
module Blog
|
6
|
-
|
7
5
|
##
|
8
6
|
# A store of all the blog articles in the site, with accessors
|
9
7
|
# for the articles by various dimensions. Accessed via "blog" in
|
10
8
|
# templates.
|
11
9
|
##
|
12
10
|
class BlogData
|
13
|
-
|
14
11
|
include UriTemplates
|
15
12
|
extend Gem::Deprecate
|
16
13
|
|
@@ -42,8 +39,8 @@ module Middleman
|
|
42
39
|
|
43
40
|
@source_template = uri_template options.sources
|
44
41
|
@permalink_template = uri_template options.permalink
|
45
|
-
@subdir_template = uri_template options.sources.sub(/(\.[^.{}\/]+)?$/,
|
46
|
-
@subdir_permalink_template = uri_template options.permalink.sub(/(\.[^.{}\/]+)?$/,
|
42
|
+
@subdir_template = uri_template options.sources.sub(/(\.[^.{}\/]+)?$/, '/{+path}')
|
43
|
+
@subdir_permalink_template = uri_template options.permalink.sub(/(\.[^.{}\/]+)?$/, '/{+path}')
|
47
44
|
end
|
48
45
|
|
49
46
|
##
|
@@ -52,7 +49,7 @@ module Middleman
|
|
52
49
|
# @return [Array<Middleman::Sitemap::Resource>]
|
53
50
|
##
|
54
51
|
def articles
|
55
|
-
@_articles.select(
|
52
|
+
@_articles.select(&(options.filter || proc { |a| a })).sort_by(&:date).reverse
|
56
53
|
end
|
57
54
|
|
58
55
|
##
|
@@ -64,8 +61,8 @@ module Middleman
|
|
64
61
|
# @param [Symbol] locale Language to match (optional, defaults to I18n.locale).
|
65
62
|
# @return [Array<Middleman::Sitemap::Resource>]
|
66
63
|
##
|
67
|
-
def local_articles(
|
68
|
-
|
64
|
+
def local_articles(locale = ::I18n.locale)
|
65
|
+
articles_by_locale(locale)
|
69
66
|
end
|
70
67
|
deprecate :local_articles, :articles_by_locale, 2017, 5
|
71
68
|
|
@@ -78,9 +75,9 @@ module Middleman
|
|
78
75
|
#
|
79
76
|
# @todo should use the @_articles if represented in this method.
|
80
77
|
##
|
81
|
-
def articles_by_locale(
|
82
|
-
locale = locale.to_sym if locale.
|
83
|
-
articles.select { |
|
78
|
+
def articles_by_locale(locale = ::I18n.locale)
|
79
|
+
locale = locale.to_sym if locale.is_a? String
|
80
|
+
articles.select { |article| article.locale == locale }
|
84
81
|
end
|
85
82
|
|
86
83
|
##
|
@@ -90,19 +87,16 @@ module Middleman
|
|
90
87
|
# @return [Hash<String, Array<Middleman::Sitemap::Resource>>]
|
91
88
|
##
|
92
89
|
def tags
|
93
|
-
|
94
90
|
tags = {}
|
95
91
|
|
96
92
|
# Reference the filtered articles
|
97
93
|
articles.each do |article|
|
98
|
-
|
99
94
|
# Reference the tags assigned to an article
|
100
95
|
article.tags.each do |tag|
|
101
96
|
# tag = safe_parameterize(tag)
|
102
97
|
tags[tag] ||= []
|
103
98
|
tags[tag] << article
|
104
99
|
end
|
105
|
-
|
106
100
|
end
|
107
101
|
|
108
102
|
# Return tags
|
@@ -144,7 +138,7 @@ module Middleman
|
|
144
138
|
next unless publishable?(article)
|
145
139
|
|
146
140
|
# Add extra parameters from the URL to the page metadata
|
147
|
-
extra_data = params.except
|
141
|
+
extra_data = params.except 'year', 'month', 'day', 'title', 'lang', 'locale'
|
148
142
|
article.add_metadata page: extra_data unless extra_data.empty?
|
149
143
|
|
150
144
|
# compute output path: substitute date parts to path pattern
|
@@ -158,13 +152,13 @@ module Middleman
|
|
158
152
|
# figure out the matching article for this subdirectory file
|
159
153
|
article_path = @source_template.expand(params).to_s
|
160
154
|
|
161
|
-
if article = @app.sitemap.find_resource_by_path(article_path)
|
155
|
+
if (article = @app.sitemap.find_resource_by_path(article_path))
|
162
156
|
# The article may not yet have been processed, so convert it here.
|
163
157
|
article = convert_to_article(article)
|
164
158
|
next unless publishable?(article)
|
165
159
|
|
166
160
|
# Add extra parameters from the URL to the page metadata
|
167
|
-
extra_data = params.except
|
161
|
+
extra_data = params.except 'year', 'month', 'day', 'title', 'lang', 'locale'
|
168
162
|
article.add_metadata page: extra_data unless extra_data.empty?
|
169
163
|
|
170
164
|
# The subdir path is the article path with the index file name
|
@@ -208,25 +202,25 @@ module Middleman
|
|
208
202
|
# @param [Hash] extra More options to be merged in on top.
|
209
203
|
# @return [Hash] options
|
210
204
|
##
|
211
|
-
def permalink_options(resource, extra={})
|
205
|
+
def permalink_options(resource, extra = {})
|
212
206
|
# Allow any frontmatter data to be substituted into the permalink URL
|
213
|
-
params = resource.metadata[:page].slice
|
207
|
+
params = resource.metadata[:page].slice(*@permalink_template.variables.map(&:to_sym))
|
214
208
|
|
215
209
|
params.each do |k, v|
|
216
210
|
params[k] = safe_parameterize(v)
|
217
211
|
end
|
218
212
|
|
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)
|
213
|
+
params
|
214
|
+
.merge(date_to_params(resource.date))
|
215
|
+
.merge(lang: resource.lang.to_s, locale: resource.locale.to_s, title: resource.slug)
|
216
|
+
.merge(extra)
|
223
217
|
end
|
224
218
|
|
225
219
|
##
|
226
220
|
#
|
227
221
|
##
|
228
|
-
def convert_to_article(
|
229
|
-
return resource if resource.is_a?(
|
222
|
+
def convert_to_article(resource)
|
223
|
+
return resource if resource.is_a?(BlogArticle)
|
230
224
|
|
231
225
|
resource.extend BlogArticle
|
232
226
|
resource.blog_controller = controller
|
@@ -241,10 +235,9 @@ module Middleman
|
|
241
235
|
##
|
242
236
|
#
|
243
237
|
##
|
244
|
-
def template_path(template, article, extras={})
|
238
|
+
def template_path(template, article, extras = {})
|
245
239
|
apply_uri_template template, permalink_options(article, extras)
|
246
240
|
end
|
247
|
-
|
248
241
|
end
|
249
242
|
end
|
250
243
|
end
|