How can I get a post excerpt in Jekyll?
Something like {{ post.content | strip_html | truncatewords: 50 }}
produces a more consistent excerpt. It gets the first 50 words and strips any formatting.
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
To get a custom length excerpt for each post, you can add a excerpt_separator
variable in front matter of your post. If you set this variable to <!--end_excerpt-->
, then post.excerpt
will include all content before <!--end_excerpt-->
.
---
excerpt_separator: <!--end_excerpt-->
---
This is included in excerpts.
This is also included in excerpts.
<!--end_excerpt-->
But this is not.
To save yourself the effort of adding excerpt_separator
to front matter of each post, you can simply set it in _config.yml
.