22

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.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • I'm not quiet sure, but I think you have to amend the Jekyll engine itself. Check out their source code on github. See line 106ff https://github.com/mojombo/jekyll/blob/master/lib/jekyll/excerpt.rb – Tobi Dec 04 '13 at 16:13
  • I hoped I could simply use something built-in. For WordPress, there are many plugins ([summy](http://wordpress.org/plugins/summy/), [advanced excerpt](http://wordpress.org/plugins/advanced-excerpt/), [search excerpt](http://scott.yang.id.au/code/search-excerpt/), ...). Maybe next weekend. When I write a plugin / adjust the `excerpt.rb`, I'll post it as an answer. (By the way: Hi Tobi :-) ) – Martin Thoma Dec 04 '13 at 18:33

2 Answers2

34

The following gives a 75 words automatic excerpt:

{{ post.content | strip_html | truncatewords:75 }}
Ahmad Ajmi
  • 7,007
  • 3
  • 32
  • 52
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
6

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.

wklchris
  • 171
  • 1
  • 4