Skip to content

Instantly share code, notes, and snippets.

@bit-dragon
Created June 7, 2012 19:55
Show Gist options
  • Save bit-dragon/2891180 to your computer and use it in GitHub Desktop.
Save bit-dragon/2891180 to your computer and use it in GitHub Desktop.
Plugin to truncate and add an anchor "read more" in the posts of jekyll
<div class="">
<div class="entry">
<h2 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="byline">Escrito el {{ post.date | date:"%d/%m/%Y" }}</div>
<div class="body">
{% if hide_extended %}
{% if post.readmore %}
{{ post.content | truncate }}
<a href="{{ post.url }}/#more" class="more-link"><span class="readmore">Read more»</span></a>
{% else %}
{{ post.content }}
{% endif %}
{% endif %}
</div>
<div class='footer'>
</div>
<br />
<br />
</div>
</div>
module Jekyll
class Post
alias_method :original_to_liquid, :to_liquid
def to_liquid
original_to_liquid.deep_merge({
'readmore' => content.match('<!--more-->') ? content.split('<!--more-->').first : nil
})
end
end
module ReadMe
def truncate content
more_tag = '<!--more-->'
if content.match more_tag
content = content.match(more_tag) ? content.split('<!--more-->').first : nil
content += '... '
end
content
end
end
end
Liquid::Template.register_filter(Jekyll::ReadMe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment