How can I get a post excerpt in Jekyll?

corazza picture corazza · Oct 15, 2013 · Viewed 18.2k times · Source

I'm creating a new blog using Jekyll.

On the main page, there will be a list of my 10 most recent posts.

The entries on this list will include a title, the post date, and an excerpt, most likely the first paragraph.

I'm only familiar with using Jekyll for basic templates, so I can either put only a variable in the page, or include the entire post.

Is there a way to somehow avoid using post.content in the paginator, and only include up to a certain point in the post, which I define (e.g. ``{% endexcerpt %}`?

Answer

Joel Hamme picture Joel Hamme · May 6, 2014

Something like {{ post.content | strip_html | truncatewords: 50 }} produces a more consistent excerpt. It gets the first 50 words and strips any formatting.