Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a longer automatic excerpt in Jekyll?

Tags:

jekyll

liquid

Currently, I include excerpts like this:

{{ post.excerpt | strip_html }}

But this seems to give only the first paragraph. But I would like to get a fixed number of words.

Or better: I would like to define a maximum number of characters and get so many words that

  • the number of characters is less than the maximum
  • one word more would be over the maximum number of characters

Is there a way to do this with Jekyll (1.3.1)?

edit: <!-- more --> is not an answer! I think excerpting should work automatically and my posts should only contain markup that is absolutely necessary.

like image 625
Martin Thoma Avatar asked Dec 02 '13 21:12

Martin Thoma


2 Answers

The following gives a 75 words automatic excerpt:

{{ post.content | strip_html | truncatewords:75 }}
like image 70
Martin Thoma Avatar answered Nov 17 '22 17:11

Martin Thoma


Actually <!-- more --> is the answer. At least, it works well now.

  1. Add this line to your _config.yml:

    excerpt_separator: "<!-- more -->"

  2. Then add this to each post in your site:

    <!-- more -->

Hope it will help.

like image 35
wklchris Avatar answered Nov 17 '22 17:11

wklchris