Created
May 7, 2012 07:45
-
-
Save mikeygee/2626538 to your computer and use it in GitHub Desktop.
truncate blog posts in jekyll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- using the truncate filter --> | |
{% for post in site.posts limit:10 %} | |
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2> | |
<span class="post-date">{{ post.date | date: "%B %d, %Y" }}</span> | |
{% if post.content.size > 2000 %} | |
{{ post.content | truncatewords: 300 }} <!-- bad! content gives you rendered html and you will truncate in the middle of a node --> | |
<a href="{{ post.url }}">read more</a> | |
{% else %} | |
{{ post.content }} | |
{% endif %} | |
<hr> | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- using the split filter --> | |
{% for post in site.posts limit:10 %} | |
<div class="post-preview"> | |
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2> | |
<span class="post-date">{{ post.date | date: "%B %d, %Y" }}</span> | |
{{ post.content | split:'<!--break-->' | first }} | |
{% if post.content contains '<!--break-->' %} | |
<a href="{{ post.url }}">read more</a> | |
{% endif %} | |
</div> | |
<hr> | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- In your posts file, put your marker wherever you want to cut off the post for the main blog page --> | |
--- | |
layout: post | |
title: truncate example | |
--- | |
Paragraph 1 | |
Paragraph 2 | |
<!--break--> | |
Paragraph 3 | |
Paragraph 4 |
Thank you, simple yet very useful!
Thank you so much! Useful!
{{ post.content | strip_html | truncatewords: 300 }}
Useful, thanks.
Oh, thank you 😁
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really useful!