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

Add "html_excerpts" flag to allow Atom <summary> tags to contain HTML #397

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Kronopath
Copy link

This option should be 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.

It pairs really well with excerpts_only for sites which may not want to put the entirety of each post's content in the feed, but who want to preserve the excerpt's rich formatting and content.

In my site, for example, post excerpts often have images. Its feed currently contains the entire post content, but I'm considering switching it to excerpts_only, and I'd very much prefer keeping those images intact in the feed if I do switch.

Note that this passes the W3C validator with no warnings, since feed.xml already uses type="html" in its <summary> tags. And since it's an option, and not a change in the default behaviour, it shouldn't break existing content.

This PR also comes complete with tests and documentation!

The test checks this by verifying that the newlines in the "pre" post are converted to spaces.
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 `<summary>` tags.

[1]: https://www.kronopath.com/blog/
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.
@Kronopath
Copy link
Author

Also I'm aware that this somewhat conflicts with my other changes in #396. Happy to resolve those conflicts later on.

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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant