Skip to content

Instantly share code, notes, and snippets.

@Narga
Forked from stympy/excerpt.rb
Created August 24, 2013 17:12
Show Gist options
  • Save Narga/6329259 to your computer and use it in GitHub Desktop.
Save Narga/6329259 to your computer and use it in GitHub Desktop.
# This goes in _plugins/excerpt.rb
module Jekyll
class Post
alias_method :original_to_liquid, :to_liquid
def to_liquid
original_to_liquid.deep_merge({
'excerpt' => content.match('<!--more-->') ? content.split('<!--more-->').first : nil
})
end
end
module Filters
def mark_excerpt(content)
content.gsub('<!--more-->', '<p><span id="more"></span></p>')
end
end
end
<!-- This snippet checks for an excerpt variable that I assign to true on my index pages, but not on the post pages, then checks to see if the post has an excerpt to see if it should render the excerpt of the post or the whole thing -->
<div class="entry">
{% if excerpt and post.excerpt %}
{{ post.excerpt }}
<p> <a href="{{ post.url }}/#more" class="more-link"><span class="readmore">Read the rest of this entry »</span></a></p>
{% else %}
{{ post.content | mark_excerpt }}
{% endif %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment