Merge pull request #1004 from uu59/fix_limit_posts_from_cli
Fix `jekyll serve --limit_posts n` failed
This commit is contained in:
commit
7efd0a8d11
|
@ -48,7 +48,7 @@ command :build do |c|
|
||||||
|
|
||||||
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
||||||
c.option '--future', 'Publishes posts with a future date'
|
c.option '--future', 'Publishes posts with a future date'
|
||||||
c.option '--limit_posts MAX_POSTS', 'Limits the number of posts to parse and publish'
|
c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish'
|
||||||
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
||||||
c.option '--lsi', 'Use LSI for improved related posts'
|
c.option '--lsi', 'Use LSI for improved related posts'
|
||||||
c.option '--drafts', 'Render posts in the _drafts folder'
|
c.option '--drafts', 'Render posts in the _drafts folder'
|
||||||
|
@ -66,7 +66,7 @@ command :serve do |c|
|
||||||
|
|
||||||
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
||||||
c.option '--future', 'Publishes posts with a future date'
|
c.option '--future', 'Publishes posts with a future date'
|
||||||
c.option '--limit_posts MAX_POSTS', 'Limits the number of posts to parse and publish'
|
c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish'
|
||||||
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
||||||
c.option '--lsi', 'Use LSI for improved related posts'
|
c.option '--lsi', 'Use LSI for improved related posts'
|
||||||
c.option '--drafts', 'Render posts in the _drafts folder'
|
c.option '--drafts', 'Render posts in the _drafts folder'
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Jekyll
|
||||||
|
|
||||||
'safe' => false,
|
'safe' => false,
|
||||||
'show_drafts' => nil,
|
'show_drafts' => nil,
|
||||||
'limit_posts' => nil,
|
'limit_posts' => 0,
|
||||||
'lsi' => false,
|
'lsi' => false,
|
||||||
'future' => true, # remove and make true just default
|
'future' => true, # remove and make true just default
|
||||||
'pygments' => true, # remove and make true just default
|
'pygments' => true, # remove and make true just default
|
||||||
|
|
|
@ -62,8 +62,8 @@ module Jekyll
|
||||||
self.categories = Hash.new { |hash, key| hash[key] = [] }
|
self.categories = Hash.new { |hash, key| hash[key] = [] }
|
||||||
self.tags = Hash.new { |hash, key| hash[key] = [] }
|
self.tags = Hash.new { |hash, key| hash[key] = [] }
|
||||||
|
|
||||||
if !self.limit_posts.nil? && self.limit_posts < 1
|
if self.limit_posts < 0
|
||||||
raise ArgumentError, "Limit posts must be nil or >= 1"
|
raise ArgumentError, "limit_posts must not be a negative number"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ module Jekyll
|
||||||
self.posts.sort!
|
self.posts.sort!
|
||||||
|
|
||||||
# limit the posts if :limit_posts option is set
|
# limit the posts if :limit_posts option is set
|
||||||
if limit_posts
|
if limit_posts > 0
|
||||||
limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
|
limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
|
||||||
self.posts = self.posts[-limit, limit]
|
self.posts = self.posts[-limit, limit]
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,8 +58,19 @@ class TestGeneratedSite < Test::Unit::TestCase
|
||||||
assert_equal 5, @site.posts.size
|
assert_equal 5, @site.posts.size
|
||||||
end
|
end
|
||||||
|
|
||||||
should "ensure limit posts is 1 or more" do
|
should "ensure limit posts is 0 or more" do
|
||||||
assert_raise ArgumentError do
|
assert_raise ArgumentError do
|
||||||
|
clear_dest
|
||||||
|
stub(Jekyll).configuration do
|
||||||
|
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => -1})
|
||||||
|
end
|
||||||
|
|
||||||
|
@site = Site.new(Jekyll.configuration)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "acceptable limit post is 0" do
|
||||||
|
assert_nothing_raised ArgumentError do
|
||||||
clear_dest
|
clear_dest
|
||||||
stub(Jekyll).configuration do
|
stub(Jekyll).configuration do
|
||||||
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
|
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
|
||||||
|
|
Loading…
Reference in New Issue