Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a post excerpt in Jekyll?

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 %}`?

like image 650
corazza Avatar asked Oct 15 '13 19:10

corazza


2 Answers

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

like image 67
Joel Meyer-Hamme Avatar answered Oct 13 '22 08:10

Joel Meyer-Hamme


Sure, you can use {{ post.excerpt }} in place of {{ post.content }}.

You can also manually override the automatically generated excerpts if you don't like them.

Full documentation on how to do this here: http://jekyllrb.com/docs/posts/#post-excerpts

like image 32
Brian Willis Avatar answered Oct 13 '22 07:10

Brian Willis