Skip to content

Instantly share code, notes, and snippets.

@jwebcat
Created April 3, 2013 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwebcat/5299228 to your computer and use it in GitHub Desktop.
Save jwebcat/5299228 to your computer and use it in GitHub Desktop.
module Jekyll
class Excerpt < Liquid::Block
def render(context)
# Get the current post's post object
id = context["page"]["id"]
posts = context.registers[:site].posts
post = posts [posts.index {|post| post.id == id}]
# Put the block contents into the post's excerpt field,
# and also return those contents
post.data["excerpt"] = super
end
end
end
Liquid::Template.register_tag('excerpt', Jekyll::Excerpt)
{% for post in site.posts %}
{% if post.excerpt %}
{{ post.excerpt | markdownify }}
{% else %}
{{ post.content }}
{% endif %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment