Skip to content

Instantly share code, notes, and snippets.

@claws
Created March 3, 2012 07:45
Show Gist options
  • Save claws/1964919 to your computer and use it in GitHub Desktop.
Save claws/1964919 to your computer and use it in GitHub Desktop.
A simple excerpt filter for use with Jekyll. Perhaps there are better ways but I couldn't find anything suitable. It extracts post content in between "<!-- excerpt start -->" and "<!-- excerpt end -->". Change the excerpt delimiters to suit your needs.
layout title
post
Test Post

This is a test post.

This content comes after the excerpt.

# This goes in _plugins/excerpt.rb
module Jekyll
module ExcerptFilter
def extract_excerpt(input)
input.split('<!-- excerpt end -->')[0].split('<!-- excerpt start -->')[1]
end
end
end
Liquid::Template.register_filter(Jekyll::ExcerptFilter)
---
layout: default
title: "Main Page"
---
<div class="posts">
{% for post in site.posts limit:5 %}
<div class="post">
<div class="title"><a href="{{ post.url }}">{{post.title }}</a></div>
<div class="date">Posted on {{ post.date | date: "%B %d %Y" }}</div>
<div class="excerpt">{{ post.content | extract_excerpt }}</div>
<p><a href="{{post.url}}">Read more »</a></p>
</div>
<hr />
{% endfor %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment