Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excerpt only flag #287

Merged
merged 4 commits into from
Nov 7, 2019
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ feed:
- updates
```

## Excerpt Only flag

Optional flag `excerpt_only` allows you to exclude post content from the Atom feed. Default value is `false` for backward compatibility.

When in `config.yml` is `true` than all posts in feed will be without `<content>` tags.

```yml
feed:
excerpt_only: true
```

The same flag can be used directly in post file. It will be disable `<content>` tag for selected post.
Settings in post file has higher priority than in config file.


## Contributing

1. Fork it (https://github.com/jekyll/jekyll-feed/fork)
Expand Down
5 changes: 4 additions & 1 deletion lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
<published>{{ post.date | date_to_xmlschema }}</published>
<updated>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</updated>
<id>{{ post.id | absolute_url | xml_escape }}</id>
<content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}">{{ post.content | strip | xml_escape }}</content>
{% assign excerpt_only = post.feed.excerpt_only | default: site.feed.excerpt_only %}
{% unless excerpt_only %}
<content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}">{{ post.content | strip | xml_escape }}</content>
{% endunless %}

{% assign post_author = post.author | default: post.authors[0] | default: site.author %}
{% assign post_author = site.data.authors[post_author] | default: post_author %}
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/_posts/2015-08-08-stuck-in-the-middle.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
---
feed:
excerpt_only: true
---

This content should not be in feed.
38 changes: 38 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,42 @@
end
end
end

context "excerpt_only flag" do
context "backward compatibility for no excerpt_only flag" do
it "should be in contents" do
expect(contents).to match '<content '
end
end

context "when site.excerpt_only flag is true" do
let(:overrides) do
{ "feed" => { "excerpt_only" => true } }
end

it "should not set any contents" do
expect(contents).to_not match '<content '
end
end

context "when site.excerpt_only flag is false" do
let(:overrides) do
{ "feed" => { "excerpt_only" => false } }
end

it "should be in contents" do
expect(contents).to match '<content '
end
end

context "when post.excerpt_only flag is true" do
let(:overrides) do
{ "feed" => { "excerpt_only" => false } }
end

it "should not be in contents" do
expect(contents).to_not match "This content should not be in feed.</content>"
end
end
end
end