簡體   English   中英

Jekyll僅在一篇文章中顯示摘錄

[英]Jekyll shows excerpt only on one post

我試圖在首頁上顯示這些文章的摘錄,但它似乎僅適用於一篇文章。 摘錄是這樣插入的:

{% 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 %}

這些帖子看起來像這樣,第一個稱為"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.

第二個名為"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.

為什么第二篇文章的摘錄沒有按預期工作? 我是否錯過了配置中的某些內容? 我還嘗試添加更多帖子,並且摘錄僅在第一篇帖子中可以正常使用。 所有后續的帖子都具有帖子列表中顯示的所有文本,沒有任何段落格式-它全部都擠在一個段落中。

您需要一個摘錄后的分隔符。

正如Jekyll文檔顯示的摘錄中的內容一樣

因為Jekyll抓住了第一段,所以您無需將摘錄用p標簽包裝,這已經為您完成了。

然后,如果您繼續閱讀...。

如果您不喜歡自動生成的帖子摘錄 ,則可以通過將excerpt值添加到帖子的YAML Front Matter中來顯式覆蓋它。 或者,您可以選擇在帖子的YAML前端問題中定義自定義excerpt_separator

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

您還可以在_config.yml配置文件中全局設置excerpt_separator。

您的帖子需要分隔符 ,以便手動告訴Jekyll帖子的顯示位置以及截止位置。 默認值應為<!--more--> ,因此請繼續將其放在第二篇文章中。 如果要使用自定義名稱,只需轉到_config.yml並添加excerpt_separator: <!-- what you want here --> 摘錄通常以注釋的形式出現,以使讀者看不到它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM