Skip to content

Instantly share code, notes, and snippets.

@benbalter
Last active June 10, 2024 21:15
Show Gist options
  • Save benbalter/5555369 to your computer and use it in GitHub Desktop.
Save benbalter/5555369 to your computer and use it in GitHub Desktop.
Example of how to use Jekyll's `excerpt` tag.

If your post looked something like:

# Awesome Blog Post

Here is an example post to show how to use the new `excerpt` tag.

The excerpt tag provides a quick and easy way to tease a post by exposing only the first paragraph such as on a blog index page.

Then in your template, you could create an index file like this:

<ul>
{% for post in site.posts %}
  <li>
    <a href="{% post.permalink %}">{% post.title %}</a>
    <p>{{ post.excerpt }}</p>
  </li>
{% endfor %}
</ul>

Which would produce:

@vkatariya8
Copy link

I have an image to start off my post, and the excerpt shows only the image. How can I show text and not the image?

@herodrigues
Copy link

@vkatariya8 I have the same situation here. My "solution" was put the image at the end of the post.

@tphbtd
Copy link

tphbtd commented Oct 4, 2015

@vkatariya8 I have excerpt_separator: "<!--more-->" in my _config.yml. In the post, I then place an image then the first paragraph (the default excerpt) followed by <!--more-->.

@eonist
Copy link

eonist commented Jan 15, 2016

This didn't work for me either, I had to escape the html more comment inside the liquid expand. Then it worked.

@rudzainy
Copy link

rudzainy commented Mar 7, 2016

I believe the excerpt method takes the whole first paragraph if you don't specify the separator.

@fabiocosta0305
Copy link

Someone could say me the best excerpt_delimiter for using --- as excerpt delimiter?

@ahmadajmi
Copy link

I use the following

{{ post.content | strip_html | truncatewords:75 }}

http://stackoverflow.com/a/20483107/558777

Copy link

ghost commented Feb 27, 2017

Thanks @ahmadajmi
If you leave out "strip_html" a post image will show if it is before the truncate.
The following works as well.
{{ post.excerpt | strip_html | truncatewords:75 }}

@oDinZu
Copy link

oDinZu commented Oct 30, 2020

I use the following

{{ post.content | strip_html | truncatewords:75 }}

http://stackoverflow.com/a/20483107/558777

Awesome. I was wondering what would happen if an image was within the post.content excerpt area. I didn't want the image displayed, but only the text. Thanks for sharing! The strip_html did the trick.

@Goldendust20
Copy link

I have a one sentence paragraph, and a full paragraph below. Any way to set the excerpt to show more than one paragraph and truncate at 275?

@GarikGelios
Copy link

I have specified excerpt_separator: <!--more--> in the _config.yml file and in front matter, but it doesn't matter where I put it <!–more–>.
Upon request {{ post.excerpt }} I get all content 🙃

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