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
@@ -29,7 +29,7 @@ module Middleman
|
|
29
29
|
# @param [Number] month
|
30
30
|
# @param [Number] day
|
31
31
|
# @return [String]
|
32
|
-
def link(year, month=nil, day=nil)
|
32
|
+
def link(year, month = nil, day = nil)
|
33
33
|
template = if day
|
34
34
|
@day_link_template
|
35
35
|
elsif month
|
@@ -47,20 +47,14 @@ module Middleman
|
|
47
47
|
new_resources = []
|
48
48
|
|
49
49
|
# 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
|
50
|
+
@blog_data.articles.group_by { |a| a.date.year }.each do |year, year_articles|
|
51
|
+
new_resources << year_page_resource(year, year_articles) if @generate_year_pages && @year_template
|
54
52
|
|
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
|
53
|
+
year_articles.group_by { |a| a.date.month }.each do |month, month_articles|
|
54
|
+
new_resources << month_page_resource(year, month, month_articles) if @generate_month_pages && @month_template
|
59
55
|
|
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
|
56
|
+
month_articles.group_by { |a| a.date.day }.each do |day, day_articles|
|
57
|
+
new_resources << day_page_resource(year, month, day, day_articles) if @generate_day_pages && @day_template
|
64
58
|
end
|
65
59
|
end
|
66
60
|
end
|
@@ -109,4 +103,4 @@ module Middleman
|
|
109
103
|
end
|
110
104
|
end
|
111
105
|
end
|
112
|
-
end
|
106
|
+
end
|
@@ -3,9 +3,7 @@ require 'date'
|
|
3
3
|
require 'middleman-blog/uri_templates'
|
4
4
|
|
5
5
|
module Middleman
|
6
|
-
|
7
6
|
module Cli
|
8
|
-
|
9
7
|
##
|
10
8
|
# This class provides an "article" command for the middleman CLI.
|
11
9
|
#
|
@@ -18,7 +16,6 @@ module Middleman
|
|
18
16
|
# @todo Tags should be removed from the template if they are not required
|
19
17
|
##
|
20
18
|
class Article < ::Thor::Group
|
21
|
-
|
22
19
|
include Thor::Actions
|
23
20
|
include Blog::UriTemplates
|
24
21
|
|
@@ -27,110 +24,104 @@ module Middleman
|
|
27
24
|
# Template files are relative to this file
|
28
25
|
# @return [String]
|
29
26
|
def self.source_root
|
30
|
-
File.dirname(
|
27
|
+
File.dirname(__FILE__)
|
31
28
|
end
|
32
29
|
|
33
30
|
argument :title, type: :string
|
34
31
|
|
35
|
-
class_option
|
36
|
-
|
37
|
-
|
32
|
+
class_option 'blog',
|
33
|
+
aliases: '-b',
|
34
|
+
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
35
|
|
39
|
-
class_option
|
40
|
-
|
41
|
-
|
36
|
+
class_option 'content',
|
37
|
+
aliases: '-c',
|
38
|
+
desc: 'Content of the post'
|
42
39
|
|
43
|
-
class_option
|
44
|
-
|
45
|
-
|
40
|
+
class_option 'date',
|
41
|
+
aliases: '-d',
|
42
|
+
desc: 'The date to create the post with (defaults to now)'
|
46
43
|
|
47
|
-
class_option
|
48
|
-
|
49
|
-
|
44
|
+
class_option 'locale',
|
45
|
+
aliases: '-l',
|
46
|
+
desc: 'The locale to create the post with (defaults to I18n.default_locale if available)'
|
50
47
|
|
51
|
-
class_option
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
class_option 'edit',
|
49
|
+
aliases: '-e',
|
50
|
+
desc: 'Edit the newly created blog post',
|
51
|
+
default: false,
|
52
|
+
type: :boolean
|
56
53
|
|
57
|
-
class_option
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
54
|
+
class_option 'subdirectory',
|
55
|
+
aliases: '-s',
|
56
|
+
desc: 'Generate an article subdirectory (for directory indexes, defaults to false)',
|
57
|
+
default: false,
|
58
|
+
type: :boolean
|
62
59
|
|
63
|
-
class_option
|
64
|
-
|
65
|
-
|
60
|
+
class_option 'tags',
|
61
|
+
aliases: '-t',
|
62
|
+
desc: 'A list of comma-separated tags for the post'
|
66
63
|
|
67
64
|
def article
|
68
|
-
|
69
|
-
@
|
70
|
-
@
|
71
|
-
@
|
72
|
-
@
|
73
|
-
@tags = options[:tags] && options[:tags].split(/\s*,\s*/) || []
|
65
|
+
@content = options[:content] || ''
|
66
|
+
@date = options[:date] ? ::Time.zone.parse(options[:date]) : Time.zone.now
|
67
|
+
@locale = options[:locale] || (::I18n.default_locale if defined? ::I18n)
|
68
|
+
@slug = safe_parameterize(title)
|
69
|
+
@tags = options[:tags]&.split(/\s*,\s*/) || []
|
74
70
|
@title = title
|
75
71
|
|
76
72
|
app = ::Middleman::Application.new do
|
77
|
-
config[
|
78
|
-
config[
|
79
|
-
config[
|
80
|
-
config[
|
73
|
+
config[:mode] = :config
|
74
|
+
config[:disable_sitemap] = true
|
75
|
+
config[:watcher_disable] = true
|
76
|
+
config[:exit_before_ready] = true
|
81
77
|
end
|
82
78
|
|
83
|
-
blog_inst = if options[
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
79
|
+
blog_inst = if options[:blog]
|
80
|
+
app.extensions[:blog].find { |_key, instance| instance.options[:name] == options[:blog] }[ 1 ]
|
81
|
+
else
|
82
|
+
app.extensions[:blog].values.first
|
83
|
+
end
|
88
84
|
|
89
85
|
unless blog_inst
|
90
|
-
msg =
|
91
|
-
msg << " named #{
|
86
|
+
msg = 'Could not find an active blog instance'
|
87
|
+
msg << " named #{options[:blog]}" if options[:blog]
|
92
88
|
throw msg
|
93
89
|
end
|
94
90
|
|
95
91
|
path_template = blog_inst.data.source_template
|
96
|
-
params = date_to_params(
|
92
|
+
params = date_to_params(@date).merge(locale: @locale.to_s, title: @slug)
|
97
93
|
article_path = apply_uri_template path_template, params
|
98
|
-
absolute_article_path = File.join(
|
94
|
+
absolute_article_path = File.join(app.source_dir, article_path + blog_inst.options.default_extension)
|
99
95
|
|
100
96
|
template blog_inst.options.new_article_template, absolute_article_path
|
101
97
|
|
102
98
|
# Edit option process
|
103
|
-
if options[
|
99
|
+
if options[:edit]
|
104
100
|
|
105
|
-
editor = ENV.fetch(
|
101
|
+
editor = ENV.fetch('MM_EDITOR', ENV.fetch('EDITOR', nil))
|
106
102
|
|
107
103
|
if editor
|
108
|
-
system(
|
104
|
+
system("#{editor} #{absolute_article_path}")
|
109
105
|
else
|
110
|
-
throw
|
106
|
+
throw 'Could not find a suitable editor. Try setting the environment variable MM_EDITOR.'
|
111
107
|
end
|
112
108
|
|
113
109
|
end
|
114
110
|
|
115
111
|
# Subdirectory option process
|
116
|
-
if options[
|
117
|
-
empty_directory extract_directory_path( File.join( app.source_dir, article_path ) )
|
118
|
-
end
|
119
|
-
|
112
|
+
empty_directory extract_directory_path(File.join(app.source_dir, article_path)) if options[:subdirectory]
|
120
113
|
end
|
121
114
|
|
122
115
|
protected
|
123
116
|
|
124
|
-
def blog_instance(
|
125
|
-
return nil unless app.extensions[
|
126
|
-
|
117
|
+
def blog_instance(key)
|
118
|
+
return nil unless app.extensions[:blog]
|
119
|
+
|
120
|
+
app.extensions[:blog][key]
|
127
121
|
end
|
128
122
|
|
129
123
|
# Add to CLI
|
130
|
-
Base.register(
|
131
|
-
|
124
|
+
Base.register(self, 'article', 'article TITLE [options]', 'Create a new blog article')
|
132
125
|
end
|
133
|
-
|
134
126
|
end
|
135
|
-
|
136
127
|
end
|
@@ -2,7 +2,6 @@ require 'middleman-blog/uri_templates'
|
|
2
2
|
|
3
3
|
module Middleman
|
4
4
|
module Blog
|
5
|
-
|
6
5
|
# This adds new summary pages for arbitrarily defined blog article properties
|
7
6
|
class CustomPages
|
8
7
|
include UriTemplates
|
@@ -26,9 +25,9 @@ module Middleman
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def manipulate_resource_list(resources)
|
29
|
-
articles_by_property = @blog_data.articles
|
30
|
-
|
31
|
-
|
28
|
+
articles_by_property = @blog_data.articles
|
29
|
+
.select { |a| a.data[property] }
|
30
|
+
.group_by { |a| a.data[property] }
|
32
31
|
resources + articles_by_property.map do |property_value, articles|
|
33
32
|
build_resource(link(property_value), property_value, articles)
|
34
33
|
end
|
@@ -40,13 +39,13 @@ module Middleman
|
|
40
39
|
articles = articles.sort_by(&:date).reverse
|
41
40
|
Sitemap::ProxyResource.new(@sitemap, path, @page_template).tap do |p|
|
42
41
|
p.add_metadata locals: {
|
43
|
-
|
44
|
-
property
|
45
|
-
|
46
|
-
|
42
|
+
'page_type' => property.to_s,
|
43
|
+
property => value,
|
44
|
+
'articles' => articles,
|
45
|
+
'blog_controller' => @blog_controller
|
47
46
|
}
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
52
|
-
end
|
51
|
+
end
|
@@ -39,7 +39,7 @@ module Middleman
|
|
39
39
|
option :publish_future_dated, false, 'Whether articles with a date in the future should be considered published'
|
40
40
|
option :custom_collections, {}, 'Hash of custom frontmatter properties to collect articles on and their options (link, template)'
|
41
41
|
option :preserve_locale, false, 'Use the global Middleman I18n.locale instead of the lang in the article\'s frontmatter'
|
42
|
-
option :new_article_template, File.expand_path('
|
42
|
+
option :new_article_template, File.expand_path('commands/article.tt', __dir__), 'Path (relative to project root) to an ERb template that will be used to generate new articles from the "middleman article" command.'
|
43
43
|
option :default_extension, '.markdown', 'Default template extension for articles (used by "middleman article")'
|
44
44
|
|
45
45
|
# @return [BlogData] blog data for this blog, which has all information about the blog articles
|
@@ -61,9 +61,9 @@ module Middleman
|
|
61
61
|
attr_reader :custom_pages
|
62
62
|
|
63
63
|
# Helpers for use within templates and layouts.
|
64
|
-
self.defined_helpers = [
|
64
|
+
self.defined_helpers = [Middleman::Blog::Helpers]
|
65
65
|
|
66
|
-
def initialize(app, options_hash={}, &block)
|
66
|
+
def initialize(app, options_hash = {}, &block)
|
67
67
|
super
|
68
68
|
|
69
69
|
@custom_pages = {}
|
@@ -88,7 +88,7 @@ module Middleman
|
|
88
88
|
options.month_link = File.join(options.prefix, options.month_link)
|
89
89
|
options.day_link = File.join(options.prefix, options.day_link)
|
90
90
|
|
91
|
-
options.custom_collections.each do |
|
91
|
+
options.custom_collections.each do |_key, opts|
|
92
92
|
opts[:link] = File.join(options.prefix, opts[:link])
|
93
93
|
end
|
94
94
|
end
|
@@ -99,7 +99,7 @@ module Middleman
|
|
99
99
|
found_name = nil
|
100
100
|
|
101
101
|
app.extensions[:blog].values.each_with_index do |ext, i|
|
102
|
-
found_name = "blog#{i+1}" if ext == self
|
102
|
+
found_name = "blog#{i + 1}" if ext == self
|
103
103
|
end
|
104
104
|
|
105
105
|
found_name
|
@@ -119,9 +119,8 @@ module Middleman
|
|
119
119
|
Time.zone = app.config[:time_zone] if app.config[:time_zone]
|
120
120
|
time_zone = Time.zone || 'UTC'
|
121
121
|
zone_default = Time.find_zone!(time_zone)
|
122
|
-
unless zone_default
|
123
|
-
|
124
|
-
end
|
122
|
+
raise 'Value assigned to time_zone not recognized.' unless zone_default
|
123
|
+
|
125
124
|
Time.zone_default = zone_default
|
126
125
|
|
127
126
|
# Initialize blog with options
|
@@ -26,25 +26,21 @@ module Middleman
|
|
26
26
|
#
|
27
27
|
# @param [Symbol, String] blog_name Optional name of the blog to get a controller for.
|
28
28
|
# @return [BlogExtension]
|
29
|
-
def blog_controller(blog_name=nil)
|
29
|
+
def blog_controller(blog_name = nil)
|
30
30
|
if !blog_name && current_resource
|
31
31
|
blog_name = current_resource.metadata[:page][:blog]
|
32
32
|
|
33
|
-
|
33
|
+
unless blog_name
|
34
34
|
blog_controller = current_resource.blog_controller if current_resource.respond_to?(:blog_controller)
|
35
35
|
return blog_controller if blog_controller
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
# In multiblog situations, force people to specify the blog
|
40
|
-
if !blog_name && blog_instances.size > 1
|
41
|
-
raise "You have more than one blog so you must either use the flag --blog (ex. --blog 'myBlog') when calling this method, or add blog: [blog_name] to your page's frontmatter"
|
42
|
-
end
|
40
|
+
raise "You have more than one blog so you must either use the flag --blog (ex. --blog 'myBlog') when calling this method, or add blog: [blog_name] to your page's frontmatter" if !blog_name && blog_instances.size > 1
|
43
41
|
|
44
42
|
# Warn if a non-existent blog name provided
|
45
|
-
if blog_name && !blog_instances.
|
46
|
-
raise "Non-existent blog name provided: #{blog_name}."
|
47
|
-
end
|
43
|
+
raise "Non-existent blog name provided: #{blog_name}." if blog_name && !blog_instances.key?(blog_name.to_sym)
|
48
44
|
|
49
45
|
blog_name ||= blog_instances.keys.first
|
50
46
|
blog_instances[blog_name.to_sym]
|
@@ -56,14 +52,14 @@ module Middleman
|
|
56
52
|
# @param [Symbol, String] blog_name Optional name of the blog to get data for.
|
57
53
|
# Blogs can be named as an option or will default to 'blog0', 'blog1', etc..
|
58
54
|
# @return [BlogData]
|
59
|
-
def blog(blog_name=nil)
|
55
|
+
def blog(blog_name = nil)
|
60
56
|
blog_controller(blog_name).data
|
61
57
|
end
|
62
58
|
|
63
59
|
# Determine whether the currently rendering template is a {BlogArticle}.
|
64
60
|
# This can be useful in layouts and helpers.
|
65
61
|
# @return [Boolean]
|
66
|
-
def is_blog_article?
|
62
|
+
def is_blog_article? # rubocop:disable Naming/PredicateName
|
67
63
|
!current_article.nil?
|
68
64
|
end
|
69
65
|
|
@@ -71,18 +67,14 @@ module Middleman
|
|
71
67
|
# @return [BlogArticle]
|
72
68
|
def current_article
|
73
69
|
article = current_resource
|
74
|
-
|
75
|
-
article
|
76
|
-
else
|
77
|
-
nil
|
78
|
-
end
|
70
|
+
article if article&.is_a?(BlogArticle)
|
79
71
|
end
|
80
72
|
|
81
73
|
# Get a path to the given tag page, based on the +taglink+ blog setting.
|
82
74
|
# @param [String] tag
|
83
75
|
# @param [Symbol, String] blog_name Optional name of the blog to use.
|
84
76
|
# @return [String]
|
85
|
-
def tag_path(tag, blog_name=nil)
|
77
|
+
def tag_path(tag, blog_name = nil)
|
86
78
|
build_url blog_controller(blog_name).tag_pages.link(tag)
|
87
79
|
end
|
88
80
|
|
@@ -90,7 +82,7 @@ module Middleman
|
|
90
82
|
# @param [Number] year
|
91
83
|
# @param [Symbol, String] blog_name Optional name of the blog to use.
|
92
84
|
# @return [String]
|
93
|
-
def blog_year_path(year, blog_name=nil)
|
85
|
+
def blog_year_path(year, blog_name = nil)
|
94
86
|
build_url blog_controller(blog_name).calendar_pages.link(year)
|
95
87
|
end
|
96
88
|
|
@@ -99,7 +91,7 @@ module Middleman
|
|
99
91
|
# @param [Number] month
|
100
92
|
# @param [Symbol, String] blog_name Optional name of the blog to use.
|
101
93
|
# @return [String]
|
102
|
-
def blog_month_path(year, month, blog_name=nil)
|
94
|
+
def blog_month_path(year, month, blog_name = nil)
|
103
95
|
build_url blog_controller(blog_name).calendar_pages.link(year, month)
|
104
96
|
end
|
105
97
|
|
@@ -109,7 +101,7 @@ module Middleman
|
|
109
101
|
# @param [Number] day
|
110
102
|
# @param [Symbol, String] blog_name Optional name of the blog to use.
|
111
103
|
# @return [String]
|
112
|
-
def blog_day_path(year, month, day, blog_name=nil)
|
104
|
+
def blog_day_path(year, month, day, blog_name = nil)
|
113
105
|
build_url blog_controller(blog_name).calendar_pages.link(year, month, day)
|
114
106
|
end
|
115
107
|
|
@@ -123,13 +115,13 @@ module Middleman
|
|
123
115
|
# Returns the list of articles to display on this particular page (when using pagination).
|
124
116
|
# @param [Symbol, String] blog_name Optional name of the blog to use.
|
125
117
|
# @return [Array<Middleman::Sitemap::Resource>]
|
126
|
-
def page_articles(blog_name=nil)
|
118
|
+
def page_articles(blog_name = nil)
|
127
119
|
meta = current_resource.metadata
|
128
120
|
limit = current_resource.data[:per_page]
|
129
121
|
|
130
122
|
# "articles" local variable is populated by Calendar and Tag page generators
|
131
123
|
# If it's not set then use the complete list of articles
|
132
|
-
articles = meta[:locals][
|
124
|
+
articles = meta[:locals]['articles'] || blog(blog_name).articles
|
133
125
|
|
134
126
|
limit ? articles.first(limit) : articles
|
135
127
|
end
|
@@ -142,12 +134,11 @@ module Middleman
|
|
142
134
|
# @param [Symbol] property Custom property which is being used to collect articles on
|
143
135
|
# @private
|
144
136
|
def self.generate_custom_helper(property)
|
145
|
-
define_method :"#{property}_path" do |value, blog_name=nil|
|
137
|
+
define_method :"#{property}_path" do |value, blog_name = nil|
|
146
138
|
custom_pages = blog_controller(blog_name).custom_pages
|
147
139
|
|
148
|
-
|
149
|
-
|
150
|
-
end
|
140
|
+
raise "This blog does not know about the custom property #{property.inspect}" unless custom_pages.key?(property)
|
141
|
+
|
151
142
|
build_url custom_pages[property].link(value)
|
152
143
|
end
|
153
144
|
end
|
@@ -159,4 +150,4 @@ module Middleman
|
|
159
150
|
end
|
160
151
|
end
|
161
152
|
end
|
162
|
-
end
|
153
|
+
end
|
@@ -7,7 +7,7 @@ module Middleman
|
|
7
7
|
class Paginator
|
8
8
|
include UriTemplates
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(app, blog_controller)
|
11
11
|
@app = app
|
12
12
|
@blog_controller = blog_controller
|
13
13
|
@per_page = blog_controller.options.per_page
|
@@ -33,8 +33,8 @@ module Middleman
|
|
33
33
|
# "articles" local variable is populated by Calendar and Tag page generators
|
34
34
|
# If it's not set then use the complete list of articles
|
35
35
|
# TODO: Some way to allow the frontmatter to specify the article filter?
|
36
|
-
articles = md[:locals][
|
37
|
-
articles.select!{|article| article.lang == md[:options][:locale]} if md.fetch(:options, false)
|
36
|
+
articles = md[:locals]['articles'] || @blog_controller.data.articles
|
37
|
+
articles.select! { |article| article.lang == md[:options][:locale] } if md.fetch(:options, false) && md[:options].fetch(:locale, false)
|
38
38
|
|
39
39
|
# Allow blog.per_page and blog.page_link to be overridden in the frontmatter
|
40
40
|
per_page = md[:page][:per_page] || @per_page
|
@@ -72,8 +72,9 @@ module Middleman
|
|
72
72
|
# Does this resource match the blog controller for this paginator?
|
73
73
|
# @return [Boolean]
|
74
74
|
def match_blog(res, md)
|
75
|
-
res_controller = md[:locals][
|
75
|
+
res_controller = md[:locals]['blog_controller'] || (res.respond_to?(:blog_controller) && res.blog_controller)
|
76
76
|
return false if res_controller && res_controller != @blog_controller
|
77
|
+
|
77
78
|
override_controller = md[:page][:blog]
|
78
79
|
return false if override_controller && override_controller.to_s != @blog_controller.name.to_s
|
79
80
|
|