Posting everything except the excerpt in Jekyll

So far I've made a custom excerpt in the config.yml file: excerpt_separator: <!--more-->

When I write a post, I would like to show an excerpt on the lists page, which works great. However, I would like to know if it is possible on the post page to post anything that is not an excerpt.

Sample article:

---
title: Lorem ipsum dolor
layout: post
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Cras in malesuada ipsum. Vivamus sapien orci, vulputate vitae 
consectetur ut, ullamcorper nec quam. Aliquam erat volutpat.

<!--more-->

Cras lacinia vehicula gravida. Cras sem quam, tincidunt at fringilla
sed, venenatis quis mauris. Praesent sit amet arcu varius mi sodales ultrices. 

      

On the posts page, I would like to show a paragraph starting with "Cras lacinia" and not Lorem ipsum.

Is this possible in Jekyll? I've searched and searched and only found ways to customize the shutter speed, but not delete it all together.

+3


source to share


2 answers


Just replace {{ content }}

with a tag that removes {{ post.excerpt }}

from{{ post.content }}

{{ post.content | remove: post.excerpt }}

      



This will print content

without excerpt

. Hop!

+8


source


I realize this is old, but the accepted answer didn't work for me ... I guess because in my instance page.content and page.excerpt were already rendered from Markdown to HTML and the tags and spaces didn match exactly.

My solution is below for anyone who comes looking. It splits the content of the message into an array containing [excerpt, remainder]:

{% assign content_array = page.content | split: site.excerpt_separator %}
{% assign excerpt_only = content_array | first %}
{% assign content_remainder = content_array | last %}

      



This requires you to define site.excerpt_separator

in _config.yml

, but for this usecase you probably don't care. Now in your template, you can simply refer to variables as needed:

<div class="post-excerpt">
  {{ excerpt_only | append: '</p>'}}
</div>

<div class="post-content">
  {{ content_remainder | remove_first: '</p>'}}
</div>

      

Filters append:

and remove_first:

should make the resulting HTML code even more correct. Examine your output and adjust if necessary.

0


source







All Articles