Skip to content
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ feed:
The same flag can be used directly in post file. It will disable `<content>` tag for selected post.
Settings in post file have higher priority than in config file.

## HTML Excerpts flag

By default, the `<summary>` portion of the feed—containing the post's excerpt or description—will be stripped of all HTML, and will have all its whitespace normalized. The optional flag `html_excerpts` turns that behaviour off, allowing your excerpts to contain full HTML content.

```yml
feed:
html_excerpts: true
```

This is useful in feeds where the excerpts have more complex content or formatting, such as when the post's `description` and `excerpt` front matter options are not set, causing Jekyll to [use the entire first paragraph of the post as the excerpt](https://jekyllrb.com/docs/posts/#post-excerpts).

## Tags

To automatically generate feeds for each tag you apply to your posts you can add a tags setting to your config:
Expand Down
6 changes: 5 additions & 1 deletion lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@

{% assign post_summary = post.description | default: post.excerpt %}
{% if post_summary and post_summary != empty %}
<summary type="html"><![CDATA[{{ post_summary | strip_html | normalize_whitespace }}]]></summary>
{% if site.feed.html_excerpts %}
<summary type="html"><![CDATA[{{ post_summary | strip }}]]></summary>
{% else %}
<summary type="html"><![CDATA[{{ post_summary | strip_html | normalize_whitespace }}]]></summary>
{% endif %}
{% endif %}

{% assign post_image = post.image.path | default: post.image %}
Expand Down
28 changes: 28 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,34 @@
expect(post.summary).to be_nil
end

it "strips HTML in summaries by default" do
post = feed.items.detect { |item| item.title.content == "Pre" }
expect(post).to_not be_nil
expect(post.summary.content).to_not match "<pre>"
end

it "normalizes whitespace in summaries by default" do
post = feed.items.detect { |item| item.title.content == "Pre" }
expect(post).to_not be_nil
expect(post.summary.content).to_not match "\n"
end

context "with feed.html_excerpts set" do
let(:overrides) { { "feed" => { "html_excerpts" => true } } }

it "doesn't strip HTML in summaries" do
post = feed.items.detect { |item| item.title.content == "Pre" }
expect(post).to_not be_nil
expect(post.summary.content).to match "<pre>"
end

it "doesn't normalize whitespace in summaries" do
post = feed.items.detect { |item| item.title.content == "Pre" }
expect(post).to_not be_nil
expect(post.summary.content).to match "\n"
end
end

context "with site.lang set" do
lang = "en_US"
let(:overrides) { { "lang" => lang } }
Expand Down