Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jekyll

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.

like image 929
dsawler Avatar asked Jun 02 '12 01:06

dsawler


2 Answers

This also works at least as of 1.0.0, is built in and is simple to use.

<ul>   {% for post in site.posts %}     <li>       <a href="{{ post.url }}">{{ post.title }}</a>       <p>{{ post.excerpt }}</p>     </li>   {% endfor %} </ul> 

See here.

like image 65
kmikael Avatar answered Oct 04 '22 08:10

kmikael


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> 
like image 37
Talon876 Avatar answered Oct 04 '22 08:10

Talon876