简体   繁体   English

Jekyll仅在一篇文章中显示摘录

[英]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" : 这些帖子看起来像这样,第一个称为"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" : 第二个名为"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 , 正如Jekyll文档显示的摘录中的内容一样

Because Jekyll grabs the first paragraph you will not need to wrap the excerpt in p tags, which is already done for you. 因为Jekyll抓住了第一段,所以您无需将摘录用p标签包装,这已经为您完成了。

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. 如果您不喜欢自动生成的帖子摘录 ,则可以通过将excerpt值添加到帖子的YAML Front Matter中来显式覆盖它。 Alternatively, you can choose to define a custom excerpt_separator in the post's YAML front matter: 或者,您可以选择在帖子的YAML前端问题中定义自定义excerpt_separator

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

You can also set the excerpt_separator globally in your _config.yml configuration file. 您还可以在_config.yml配置文件中全局设置excerpt_separator。

Your posts need the separator in order to manually tell Jekyll where to show the post until and where to cut off the text. 您的帖子需要分隔符 ,以便手动告诉Jekyll帖子的显示位置以及截止位置。 The default should be <!--more--> , so go ahead and place that in your second post. 默认值应为<!--more--> ,因此请继续将其放在第二篇文章中。 If you want to use a custom one, just go to your _config.yml and add excerpt_separator: <!-- what you want here --> . 如果要使用自定义名称,只需转到_config.yml并添加excerpt_separator: <!-- what you want here --> Excerpts are usually in the form of comments so that they aren't visible to the reader. 摘录通常以注释的形式出现,以使读者看不到它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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