diff --git a/lib/jekyll-feed/feed.xml b/lib/jekyll-feed/feed.xml index 40a221ae..afba157a 100644 --- a/lib/jekyll-feed/feed.xml +++ b/lib/jekyll-feed/feed.xml @@ -40,14 +40,17 @@ {% endif %} {% if page.tags %} - {% assign entries = site.tags[page.tags] %} + {% assign posts = site.tags[page.tags] %} {% else %} - {% assign entries = site[page.collection] %} + {% assign posts = site[page.collection] %} {% endif %} - {% assign posts = entries | where_exp: "post", "post.draft != true" | sort: "date" | reverse %} {% if page.category %} - {% assign posts = posts | where: "category",page.category %} + {% assign posts = posts | where: "category", page.category %} {% endif %} + {% unless site.show_drafts %} + {% assign posts = posts | where_exp: "post", "post.draft != true" %} + {% endunless %} + {% assign posts = posts | sort: "date" | reverse %} {% assign posts_limit = site.feed.posts_limit | default: 10 %} {% for post in posts limit: posts_limit %} diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb index 40b97cf1..e284dc30 100644 --- a/spec/jekyll-feed_spec.rb +++ b/spec/jekyll-feed_spec.rb @@ -9,7 +9,7 @@ "full_rebuild" => true, "source" => source_dir, "destination" => dest_dir, - "show_drafts" => true, + "show_drafts" => false, "url" => "http://example.org", "name" => "My awesome site", "author" => { @@ -701,4 +701,26 @@ expect(contents).to match "http://example.org/2016/04/25/author-reference.html" end end + + context "support drafts" do + context "with disable show_drafts option" do + let(:overrides) do + { "show_drafts" => false } + end + + it "should not be draft post" do + expect(contents).to_not match "a-draft.html" + end + end + + context "with enable show_drafts option" do + let(:overrides) do + { "show_drafts" => true } + end + + it "should be draft post" do + expect(contents).to match "a-draft.html" + end + end + end end