Skip to content

Instantly share code, notes, and snippets.

@drewsberry
Created July 30, 2014 15:23
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 drewsberry/200e3d3ede16a369b1e6 to your computer and use it in GitHub Desktop.
Save drewsberry/200e3d3ede16a369b1e6 to your computer and use it in GitHub Desktop.
Jekyll excerpts, split by <!--more--> by default. If not found, default to the first 500 words.
{% if post.content contains '<!--more-->' %}
{{ post.content | split:'<!--more-->' | first %}}
<p><a class="btn btn-primary btn-lg" href="{{ post.url }}">Continue reading...</a></p>
{% else %}
{{ post.content | truncate: 500 }}
<p><a class="btn btn-primary btn-lg" href="{{ post.url }}">Continue reading...</a></p>
{% endif %}
@drewsberry
Copy link
Author

You need to be careful if you're automatically truncating that you're not caught in the middle of a code block or other element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment