Skip to content

Commit 702dd89

Browse files
authored
Add support to drafts (#316)
Merge pull request 316
1 parent 9f6becf commit 702dd89

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lib/jekyll-feed/feed.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@
4040
{% endif %}
4141

4242
{% if page.tags %}
43-
{% assign entries = site.tags[page.tags] %}
43+
{% assign posts = site.tags[page.tags] %}
4444
{% else %}
45-
{% assign entries = site[page.collection] %}
45+
{% assign posts = site[page.collection] %}
4646
{% endif %}
47-
{% assign posts = entries | where_exp: "post", "post.draft != true" | sort: "date" | reverse %}
4847
{% if page.category %}
49-
{% assign posts = posts | where: "category",page.category %}
48+
{% assign posts = posts | where: "category", page.category %}
5049
{% endif %}
50+
{% unless site.show_drafts %}
51+
{% assign posts = posts | where_exp: "post", "post.draft != true" %}
52+
{% endunless %}
53+
{% assign posts = posts | sort: "date" | reverse %}
5154
{% assign posts_limit = site.feed.posts_limit | default: 10 %}
5255
{% for post in posts limit: posts_limit %}
5356
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>

spec/jekyll-feed_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"full_rebuild" => true,
1010
"source" => source_dir,
1111
"destination" => dest_dir,
12-
"show_drafts" => true,
12+
"show_drafts" => false,
1313
"url" => "http://example.org",
1414
"name" => "My awesome site",
1515
"author" => {
@@ -701,4 +701,26 @@
701701
expect(contents).to match "http://example.org/2016/04/25/author-reference.html"
702702
end
703703
end
704+
705+
context "support drafts" do
706+
context "with disable show_drafts option" do
707+
let(:overrides) do
708+
{ "show_drafts" => false }
709+
end
710+
711+
it "should not be draft post" do
712+
expect(contents).to_not match "a-draft.html"
713+
end
714+
end
715+
716+
context "with enable show_drafts option" do
717+
let(:overrides) do
718+
{ "show_drafts" => true }
719+
end
720+
721+
it "should be draft post" do
722+
expect(contents).to match "a-draft.html"
723+
end
724+
end
725+
end
704726
end

0 commit comments

Comments
 (0)