Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
Expand Down
24 changes: 23 additions & 1 deletion spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down Expand Up @@ -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