简体   繁体   中英

Jekyll shows excerpt only on one post

I'm trying to show the excerpts of the posts on the front page, but it seems to only work for one post. The excerpt is inserted like this:

{% for post in paginator.posts %}
    <div class="unit whole single-post-excerpt">
        <h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
        <p class="description">{{ post.excerpt | strip_html }}</p>
    </div>
{% endfor %}

The posts look like this, first one called "2015-08-17-first-post.markdown" :

---
layout: post
title: "The first post that works"
---
This is the first post that has a working excerpt.

That was the excerpt, and this one won't show up in the list of posts.

These two paragraphs are shown on the post page instead.

And the second one, called "2015-08-18-second-post.markdown" :

---
layout: post
title: "The second post that does not work"
---
This is the second post that does not work as intended.

This paragraph gets also added to the excerpt.

As does this one.

Why doesn't the second post's excerpt work as intended? Did I miss something in the configuration or..? I also tried adding more posts, and the excerpt works correctly only on the first post. All subsequent posts have all the text shown in the post list, with no paragraph formatting whatsoever - it's all just crammed into one paragraph.

You need a post-excerpt separator.

As the Jekyll documentation shows for post-excerpts ,

Because Jekyll grabs the first paragraph you will not need to wrap the excerpt in p tags, which is already done for you.

And then if you read on ....

If you don't like the automatically-generated post excerpt , it can be explicitly overridden by adding an excerpt value to your post's YAML Front Matter. Alternatively, you can choose to define a custom excerpt_separator in the post's YAML front matter:

 --- excerpt_separator: <!--more--> --- Excerpt <!--more--> Out-of-excerpt 

You can also set the excerpt_separator globally in your _config.yml configuration file.

Your posts need the separator in order to manually tell Jekyll where to show the post until and where to cut off the text. The default should be <!--more--> , so go ahead and place that in your second post. If you want to use a custom one, just go to your _config.yml and add excerpt_separator: <!-- what you want here --> . Excerpts are usually in the form of comments so that they aren't visible to the reader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM