Jekyll hacks - HTML excerpts
Jekyll is a really cool platform for blogs, especially if you are a geek and love Github. Nevertheless it’s fairly new and has some gaps here and there.
One of the features that I really missed was a support for post excerpts so that for longer posts you could show a shorter version on the index page.
One workaround is to use Liquid templating library’s filters to strip the content:
{{ post.content | strip_html | truncatewords: 25 }}
The downside of this is that you lose HTML tags and it’s not very convenient to control how much of the content is truncated per post.
Another alternative is to add additional attribute “excerpt” to post’s YAML Front Matter but in this case you need to duplicate some of the content.
Finally you can implement excerpt functionality as a Jekyll plugin but then you lose the convenience of the blog beeing auto-generated by Github Pages since it doesn’t support plugins.
The solution
First, mark the part of the post that you want to be truncated like this:
---
title: some post
layout: post
---
Some intro, this will be visible on the index page.
<!-- more start -->
More content, this will not be visible on the index page.
<!-- more end -->
And then use the following Liquid tag to hide the marked part on the index page:
{{ post.content | replace:'more start -->','' | replace:'<!-- more end','' }}
It simply makes the part commented out in HTML. It’s not perfect since the full content will still be included in the HTML, however it won’t be visible to your blog’s readers.
The upside is that it supports full HTML and you don’t need to duplicate any content or mess with the plugins.

