Skip to content

Commit

Permalink
Add support to drafts (#316)
Browse files Browse the repository at this point in the history
Merge pull request 316
  • Loading branch information
torrocus authored Jul 10, 2020
1 parent 9f6becf commit 702dd89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
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

0 comments on commit 702dd89

Please sign in to comment.