From 806669193f2fe71b2193fa9a643cc3eabed8844a Mon Sep 17 00:00:00 2001 From: "Gabriel B. Nunes" Date: Mon, 13 Nov 2023 22:15:17 -0800 Subject: [PATCH 1/8] Added test to verify that HTML is stripped in excerpts by default --- spec/jekyll-feed_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb index 41514d1f..fc553eac 100644 --- a/spec/jekyll-feed_spec.rb +++ b/spec/jekyll-feed_spec.rb @@ -162,6 +162,11 @@ expect(post.summary).to be_nil end + it "strips HTML in summaries by default" do + post = feed.items[3] # The "pre" file + expect(post.summary.content).to_not match "
"
+    end
+
     context "with site.lang set" do
       lang = "en_US"
       let(:overrides) { { "lang" => lang } }

From a43cf115715a46ae2d89c6bef2d9d1ac48e16ad7 Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Mon, 13 Nov 2023 22:20:58 -0800
Subject: [PATCH 2/8] Added test to verify that whitespace is normalized in
 post summaries

The test checks this by verifying that the newlines in the "pre" post are converted to spaces.
---
 spec/jekyll-feed_spec.rb | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb
index fc553eac..4e23a28f 100644
--- a/spec/jekyll-feed_spec.rb
+++ b/spec/jekyll-feed_spec.rb
@@ -167,6 +167,11 @@
       expect(post.summary.content).to_not match "
"
     end
 
+    it "normalizes whitespace in summaries by default" do
+      post = feed.items[3] # The "pre" file
+      expect(post.summary.content).to_not match "\n"
+    end
+
     context "with site.lang set" do
       lang = "en_US"
       let(:overrides) { { "lang" => lang } }

From 4776be22b70315cbc0ec72224ca907fd921831ca Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Mon, 13 Nov 2023 22:39:35 -0800
Subject: [PATCH 3/8] Add "html_summaries" option to allow summaries to output
 as full HTML

This allows posts with autogenerated excerpts (that may have images or HTML in them) to keep that HTML intact in the summary portion of the Atom feed. The default remains as having the HTML be stripped and the whitespace normalized.

This has some benefits, because the default value for a post excerpt is for it to be the entire first paragraph of each post. It's not unheard of for it to have plenty of HTML formatting and other tags.

In [my site][1], for example, post excerpts often have images, and I'd very much prefer keeping those images intact in the feed, even if using `excerpt_only` feed generation.

Note that this passes the W3C validator with no warnings, since feed.xml already uses `type="html"` in its `` tags.

[1]: https://www.kronopath.com/blog/
---
 lib/jekyll-feed/feed.xml |  6 +++++-
 spec/jekyll-feed_spec.rb | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/jekyll-feed/feed.xml b/lib/jekyll-feed/feed.xml
index 9068836f..022453e4 100644
--- a/lib/jekyll-feed/feed.xml
+++ b/lib/jekyll-feed/feed.xml
@@ -96,7 +96,11 @@
 
       {% assign post_summary = post.description | default: post.excerpt %}
       {% if post_summary and post_summary != empty %}
-        
+        {% if site.feed.html_summaries %}
+          
+        {% else %}
+          
+        {% endif %}
       {% endif %}
 
       {% assign post_image = post.image.path | default: post.image %}
diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb
index 4e23a28f..20525f53 100644
--- a/spec/jekyll-feed_spec.rb
+++ b/spec/jekyll-feed_spec.rb
@@ -172,6 +172,20 @@
       expect(post.summary.content).to_not match "\n"
     end
 
+    context "with feed.html_summaries set" do
+      let(:overrides) { { "feed" => { "html_summaries" => true } } }
+
+      it "doesn't strip HTML in summaries" do
+        post = feed.items[3] # The "pre" file
+        expect(post.summary.content).to match "
"
+      end
+
+      it "doesn't normalize whitespace in summaries" do
+        post = feed.items[3] # The "pre" file
+        expect(post.summary.content).to match "\n"
+      end
+    end
+
     context "with site.lang set" do
       lang = "en_US"
       let(:overrides) { { "lang" => lang } }

From 080ee6dd2a95f678adef383e153c63c909fdb357 Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Mon, 13 Nov 2023 22:55:10 -0800
Subject: [PATCH 4/8] Add documentation for the new "html_summaries" flag

---
 README.md | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/README.md b/README.md
index a0f9d1f2..2863a465 100644
--- a/README.md
+++ b/README.md
@@ -207,6 +207,17 @@ feed:
 The same flag can be used directly in post file. It will disable `` tag for selected post.
 Settings in post file have higher priority than in config file.
 
+## HTML Summaries flag
+
+By default, the `` 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_summaries` turns that behaviour off, allowing your excerpts to contain full HTML content.
+
+```yml
+feed:
+  html_summaries: true
+```
+
+This is useful in feeds where the summaries have more complex content or formatting, such as when the post's `description` and `excerpt` front matter options are not set, causing Jekyll to fall back to [using the 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:

From a30e2a5f84f03cb453b5dcfe2438c24b3513ebf1 Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Mon, 13 Nov 2023 23:00:23 -0800
Subject: [PATCH 5/8] Rename the flag to html_excerpts

This naming is more consistent with the "excerpts_only" flag, though it may be slightly more confusing given that this also applies to the post's "description" option. Still, consistency is key.
---
 README.md                | 8 ++++----
 lib/jekyll-feed/feed.xml | 2 +-
 spec/jekyll-feed_spec.rb | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index 2863a465..17e7829f 100644
--- a/README.md
+++ b/README.md
@@ -207,16 +207,16 @@ feed:
 The same flag can be used directly in post file. It will disable `` tag for selected post.
 Settings in post file have higher priority than in config file.
 
-## HTML Summaries flag
+## HTML Excerpts flag
 
-By default, the `` 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_summaries` turns that behaviour off, allowing your excerpts to contain full HTML content.
+By default, the `` 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_summaries: true
+  html_excerpts: true
 ```
 
-This is useful in feeds where the summaries have more complex content or formatting, such as when the post's `description` and `excerpt` front matter options are not set, causing Jekyll to fall back to [using the first paragraph of the post as the excerpt](https://jekyllrb.com/docs/posts/#post-excerpts).
+This is useful in feeds where the summaries 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
 
diff --git a/lib/jekyll-feed/feed.xml b/lib/jekyll-feed/feed.xml
index 022453e4..141d61cd 100644
--- a/lib/jekyll-feed/feed.xml
+++ b/lib/jekyll-feed/feed.xml
@@ -96,7 +96,7 @@
 
       {% assign post_summary = post.description | default: post.excerpt %}
       {% if post_summary and post_summary != empty %}
-        {% if site.feed.html_summaries %}
+        {% if site.feed.html_excerpts %}
           
         {% else %}
           
diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb
index 20525f53..04939deb 100644
--- a/spec/jekyll-feed_spec.rb
+++ b/spec/jekyll-feed_spec.rb
@@ -172,8 +172,8 @@
       expect(post.summary.content).to_not match "\n"
     end
 
-    context "with feed.html_summaries set" do
-      let(:overrides) { { "feed" => { "html_summaries" => true } } }
+    context "with feed.html_excerpts set" do
+      let(:overrides) { { "feed" => { "html_excerpts" => true } } }
 
       it "doesn't strip HTML in summaries" do
         post = feed.items[3] # The "pre" file

From bf214009255f64c00673055c84e632368e55afac Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Mon, 13 Nov 2023 23:02:38 -0800
Subject: [PATCH 6/8] Forgot to rename one instance of "summaries" to
 "excerpts"

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 17e7829f..3e326486 100644
--- a/README.md
+++ b/README.md
@@ -216,7 +216,7 @@ feed:
   html_excerpts: true
 ```
 
-This is useful in feeds where the summaries 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).
+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
 

From 3e6d5120328590759f8dc6bf855943dfce69feed Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Tue, 14 Nov 2023 01:12:59 -0800
Subject: [PATCH 7/8] Attempt to fix tests that are failing due to incorrect
 post being tested

Apparently some of the test cases are failing because instead of the "pre" post being tested, it's instead picking up the "liquid" post from just before it.

I suspect that this might be happening because the test machines are maybe configured with a date and time before 2016-04-25, meaning that they don't pick up the "author-reference" post, leading to an off-by-one error. That's my best guess, anyway.

It's not the most robust answer, since it would also likely mean that in these machines the "puts the latest 2 the posts in the feed.xml file" test would also fail. So maybe I'm wrong.

Still, to try to fix this, instead of counting the posts from the most recent, the test now instead counts from the oldest, which should hopefully be more robust to this issue.
---
 spec/jekyll-feed_spec.rb | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb
index 04939deb..eb3c34c1 100644
--- a/spec/jekyll-feed_spec.rb
+++ b/spec/jekyll-feed_spec.rb
@@ -163,12 +163,12 @@
     end
 
     it "strips HTML in summaries by default" do
-      post = feed.items[3] # The "pre" file
+      post = feed.items[-7] # The "pre" file
       expect(post.summary.content).to_not match "
"
     end
 
     it "normalizes whitespace in summaries by default" do
-      post = feed.items[3] # The "pre" file
+      post = feed.items[-7] # The "pre" file
       expect(post.summary.content).to_not match "\n"
     end
 
@@ -176,12 +176,12 @@
       let(:overrides) { { "feed" => { "html_excerpts" => true } } }
 
       it "doesn't strip HTML in summaries" do
-        post = feed.items[3] # The "pre" file
+        post = feed.items[-7] # The "pre" file
         expect(post.summary.content).to match "
"
       end
 
       it "doesn't normalize whitespace in summaries" do
-        post = feed.items[3] # The "pre" file
+        post = feed.items[-7] # The "pre" file
         expect(post.summary.content).to match "\n"
       end
     end

From 9ab43a2aadf5db00f5264a146252b45aef169206 Mon Sep 17 00:00:00 2001
From: "Gabriel B. Nunes" 
Date: Wed, 15 Nov 2023 22:33:47 -0800
Subject: [PATCH 8/8] In tests, search for post by title instead of by index

Apparently the indices just aren't consistent on jekyll-feed's test machines. Neither `feed.items[3]` nor `feed.items[-7]` can be reliably said to be the "pre" post which I use for testing in this PR.

Instead, let's just search through all the posts for whichever one is titled "Pre" and test against that one.
---
 spec/jekyll-feed_spec.rb | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb
index eb3c34c1..51f1301c 100644
--- a/spec/jekyll-feed_spec.rb
+++ b/spec/jekyll-feed_spec.rb
@@ -163,12 +163,14 @@
     end
 
     it "strips HTML in summaries by default" do
-      post = feed.items[-7] # The "pre" file
+      post = feed.items.detect { |item| item.title.content == "Pre" }
+      expect(post).to_not be_nil
       expect(post.summary.content).to_not match "
"
     end
 
     it "normalizes whitespace in summaries by default" do
-      post = feed.items[-7] # The "pre" file
+      post = feed.items.detect { |item| item.title.content == "Pre" }
+      expect(post).to_not be_nil
       expect(post.summary.content).to_not match "\n"
     end
 
@@ -176,12 +178,14 @@
       let(:overrides) { { "feed" => { "html_excerpts" => true } } }
 
       it "doesn't strip HTML in summaries" do
-        post = feed.items[-7] # The "pre" file
+        post = feed.items.detect { |item| item.title.content == "Pre" }
+        expect(post).to_not be_nil
         expect(post.summary.content).to match "
"
       end
 
       it "doesn't normalize whitespace in summaries" do
-        post = feed.items[-7] # The "pre" file
+        post = feed.items.detect { |item| item.title.content == "Pre" }
+        expect(post).to_not be_nil
         expect(post.summary.content).to match "\n"
       end
     end