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
Append appropriate closing tag to Liquid block in an excerpt #6724
Conversation
Would it make sense having full Liquid blocks in excerpts in the first place? Assuming you had something like an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this!!!!!!!
lib/jekyll/excerpt.rb
Outdated
# append appropriate closing tag (to a Liquid block), to the "head" if the | ||
# partitioning resulted in leaving the closing tag somewhere in the "tail" | ||
# partition. | ||
if head =~ %r!{%\s*(\w+).+\s*%}! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regexp's are very slow! Can we use head.include?("{%")
before we do regexp? I think this runs on every page generation...
@oe IMO, Users are responsible for the "content" within their files. I don't think Jekyll should halt the build process in such cases.. If need be, Jekyll can issue a warning that a liquid block has been handled as required in the excerpt, and may not render as expected.. but that's for another PR.. |
1fb9ab1
to
8ee06ae
Compare
@ashmaroli Alright, fair enough. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good addition 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will only close one Liquid tag, is that correct?
Could we please output a warning if we ever do this? Users should be alerted so they can provide an explicit excerpt in cases where we truncate something that we shouldn't.
lib/jekyll/excerpt.rb
Outdated
head =~ %r!{%\s*(\w+).+\s*%}! | ||
tag_name = Regexp.last_match(1) | ||
|
||
if liquid_block?(tag_name) && head.match(%r!{%\s*end#{tag_name}.+\s*%}!).nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with the .+
?
If is necessary, you can get rid of the \s*
, since .+
will also swallow any whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch.. .+
is not needed since end-tags do not take argument(s)..
yes. That is correct.. I consider excerpts that would contain multiple block-tags or nested block-tags as edge-cases which we shouldn't bother handling.. Let the build fail and leave it to the author to take appropriate action.. |
I wonder if we could have an option to fail the build when something like this happens. I would rather the build fail than have a wonky site, but I understand that is maddening when not running Jekyll locally. This change will be an improvement for many users 👍 |
I disagree.. IMO, that'd be over-engineering.. |
I mean instead of Jekyll quietly trying to patch things up, we could just let it fail. This is not over-engineering, it is our current behavior. |
ohh.. I thought you were referring to the above mentioned edge-cases.. |
Not necessary for this PR though 👍 |
@jekyllbot: merge +bug |
This prevents my blog from building, when I have Liquid in excerpts. |
Resolves #5596
If a
Liquid::Block
tag subclass gets caught between theexcerpt_separator
, then append the concerned block delimiter to the excerpt to avoid aLiquid Exception due to invalid syntax