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

Post preview shows markdown #1322

Closed
thejcannon opened this issue May 27, 2024 · 2 comments
Closed

Post preview shows markdown #1322

thejcannon opened this issue May 27, 2024 · 2 comments

Comments

@thejcannon
Copy link

👋 I'm trying out Beautiful Jekyll for a site and noticed that my post, which starts with a markdown code block is rendered quite literally in the home pages summary (E.g. the summary starts with "```text")

(Also love it so far, thanks for making this ❤️)

@daattali
Copy link
Owner

This is unfortunately working "as intended". It's not really an issue specific to this theme, it's a more general jekyll concern. I'm going to close this issue since it's not a bug with my theme, but I'll try to walk you through what's happening, so that you can try to think of a custom solution or take this info and ask in a jekyll forum about work arounds:

Jekyll has the concept of a "post excerpt" as described here https://jekyllrb.com/docs/posts/#post-excerpts and as you can see, by default it takes the first paragraph of content. Here if the code in beautiful jekyll that takes this excerpt and shows it on the home page:

{% assign excerpt_length = site.excerpt_length | default: 50 %}
{{ post.excerpt | strip_html | truncatewords: excerpt_length }}

So what's happening is that because you have a blank line inside that (poem?), jekyll treats that as a new paragraph. So it takes all the content up until that blank line, which is:

```text
It is a period of civil war.
Rebel collectors, striking
from a hidden basement,
have won their first victory
against the evil Garbage Empire.

And this it the post excerpt (if you use the excerpt_length parameter that beautifuljekyll uses, then it'll truncate the number of words). When you take the text above, jekyll does not know that this is markdown because it doesn't see the closing backticks. So it thinks the opening ticks are part of the text.

To drive this point further, I think (I haven't tested this) that if you remove blank lines from the poem, or if you ended the markdown syntax after the first paragraph, then the post excerpt on the home page will look correct.

You can also explicitly define what the excerpt should be, by adding a excerpt: YAML field in the post. On the jekyll documentation page that I linked above, you may have noticed that they talk about a excerpt_separator, perhaps you can use that so that the blank line doesn't end the excerpt.

I hope this was useful.

@thejcannon
Copy link
Author

Oh wow that's a very thorough response! That all makes perfect sense, I'll play around with some settings, thanks!

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

No branches or pull requests

2 participants