diff --git a/README.md b/README.md index 518aced7..d9a87821 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,15 @@ feed: - updates ``` +## Posts limit + +By default the plugin limits the number of posts in the feed to 10. Simply define a new limit in your config: + +```yml +feed: + posts_limit: 20 +``` + ## Collections Jekyll Feed can generate feeds for collections other than the Posts collection. This works best for chronological collections (e.g., collections with dates in the filenames). Simply define which collections you'd like feeds for in your config: diff --git a/lib/jekyll-feed/feed.xml b/lib/jekyll-feed/feed.xml index a7417ec2..e26bb7c2 100644 --- a/lib/jekyll-feed/feed.xml +++ b/lib/jekyll-feed/feed.xml @@ -43,7 +43,8 @@ {% if page.category %} {% assign posts = posts | where: "category",page.category %} {% endif %} - {% for post in posts limit: 10 %} + {% assign posts_limit = site.feed.posts_limit | default: 10 %} + {% for post in posts limit: posts_limit %} {% assign post_title = post.title | smartify | strip_html | normalize_whitespace | xml_escape %} diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb index 8df3d4d7..a1ea3a73 100644 --- a/spec/jekyll-feed_spec.rb +++ b/spec/jekyll-feed_spec.rb @@ -534,4 +534,24 @@ end end end + + context "with feed.posts_limit set to 2" do + let(:overrides) do + { "feed" => { "posts_limit" => 2 } } + end + + it "puts the latest 2 the posts in the feed.xml file" do + expect(contents).to_not match "http://example.org/news/2013/12/12/dec-the-second.html" + expect(contents).to_not match "http://example.org/news/2014/03/02/march-the-second.html" + expect(contents).to_not match "http://example.org/updates/jekyll/2014/03/04/march-the-fourth.html" + expect(contents).to_not match "http://example.org/2015/01/18/jekyll-last-modified-at.html" + expect(contents).to_not match "http://example.org/2015/02/12/strip-newlines.html" + expect(contents).to_not match "http://example.org/2015/05/12/liquid.html" + expect(contents).to_not match "http://example.org/2015/05/12/pre.html" + expect(contents).to_not match "http://example.org/2015/05/18/author-detail.html" + + expect(contents).to match "http://example.org/2015/08/08/stuck-in-the-middle.html" + expect(contents).to match "http://example.org/2016/04/25/author-reference.html" + end + end end