How to show a preview of a post? (Using Jekyll Bootstrap theme)

dsawler picture dsawler · Jun 2, 2012 · Viewed 15.2k times · Source

This is probably an easy question, but how do I show previews of my posts on the default page? I am using the Jekyll Bootstrap theme Tom.

Answer

Talon876 picture Talon876 · Jun 15, 2012

Looking through the functions here, I found strip_html and truncatewords.

Here's a sample "posts list" with 75 words of preview text.

<ul >
    {% for post in site.posts limit 4 %}
    <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></li>
        {{ post.content | strip_html | truncatewords:75}}<br>
            <a href="{{ post.url }}">Read more...</a><br><br>
    {% endfor %}
</ul>