Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display post summary on index page using Jekyll?

Tags:

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?

like image 977
Akshat Jiwan Sharma Avatar asked Mar 19 '13 10:03

Akshat Jiwan Sharma


1 Answers

Update 16 Nov, 2015

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.

Old answer

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.

like image 59
Sam Avatar answered Oct 15 '22 20:10

Sam