From 702dd896f1351f84c7d284b7867096ee3a275241 Mon Sep 17 00:00:00 2001 From: Alex Malaszkiewicz Date: Fri, 10 Jul 2020 18:54:38 +0200 Subject: [PATCH] Add support to drafts (#316) Merge pull request 316 --- lib/jekyll-feed/feed.xml | 11 +++++++---- spec/jekyll-feed_spec.rb | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) 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