How do I use markdownify in Jekyll to show an excerpt on the index

kaplan picture kaplan · May 7, 2013 · Viewed 11.1k times · Source

I'm looking to show a short excerpt of text from a longer post or page on the index page. I was going to use a custom variable in the Front Matter and grab that, but then I saw the filter for .excerpt

I see in the Jekyll docs there's something called {{ page.excerpt | markdownify }} How would I markup the markdown on a page or post in order to use that filter?

edit: Or does markdownify take the entire .md document?

Answer

Chongxu Ren picture Chongxu Ren · Aug 2, 2013

Jekyll has an option excerpt_separator, which is suitable for you. Things go like this:

In _config.yml:

excerpt_separator: <!--more-->  # you can specify your own separator, of course.

In you post:

---
layout: post
title: Foo
---

This appears in your `index.html`

This appears, too.

<!--more-->

This doesn't appear. It is separated.

Note you must type exactly <!--more-->, not <!--More--> or <!-- more -->.

In your index.html:

<!-- Loop in you posts -->
{% for post in site.posts %}
  <!-- Here's the header -->
  <header>
    <h2 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
  </header>

  <!-- Your post's summary goes here -->
  <article>{{ post.excerpt }}</article> 
{% endfor %}

The output is like this:

<header>
  <h2 class="title"><a href="Your post URL">Foo</a></h2>
</header>

<article>

This appears in your `index.html`

This appears, too.

</article>