I am using Jekyll to create a blog by following this excellent tutorial. I would like to add a post summary on the index page. I tried using:
post.content | truncatewords:50 | strip_html
it works but it displays the entire post until the 50 word count is reached. This includes the heading too. I would like to just summarize the actual content of the post. How can I structure my posts to do this?
Now Jekyll support excerpt separator, In template you can do this:
{% if post.excerpt %} {{ post.excerpt }} {% endif %}
and In global config _config.yml
you can set:
excerpt_separator: <!--more-->
and the same use with <!--more-->
html comment tag.
You can try this:
{% if post.content contains '<!--more-->' %} {{ post.content | split:'<!--more-->' | first }} {% else %} {{ post.content }} {% endif %}
and add <!--more-->
tag in the article after summary, just like Wordpress.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With