Skip to content

Commit

Permalink
Make posts limit configurable (#314)
Browse files Browse the repository at this point in the history
Merge pull request 314
  • Loading branch information
Enteee authored Jun 21, 2020
1 parent eee0245 commit 6cbf227
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
{% assign post_title = post.title | smartify | strip_html | normalize_whitespace | xml_escape %}

Expand Down
20 changes: 20 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6cbf227

Please sign in to comment.