[英]How to display an excerpt from a single post using Jekyll
我正在使用Jekyll創建一個博客網站,我想在主頁上添加一個簡短的“關於”部分。 而不是創建一個單獨的段落,我將創建一個“關於我”帖子(about-me.md)並在主頁上插入該帖子的摘錄(在其下方將是一個閱讀其余內容的鏈接)該文章)。
我在網上找到的唯一信息是關於“最新帖子”部分,利用“for”循環顯示最近的5個(或更多)帖子。 我在Jekyll文檔中找不到任何其他內容來解釋如何顯示某個特定帖子的摘錄。
我試過改變
{{ post.excerpt }}
至
{{ about-me.excerpt }}
但無濟於事。
以下是“近期帖子”的實施情況:
<div class="about-section">
<h1>About Me</h1>
<ul>
{% for post in site.posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
{{ post.excerpt }}
</li>
{% endfor %}
</ul>
</div>
這可以顯示最近的帖子,包括摘錄。 我只需要在標題下面的'about-me.md'帖子中顯示摘錄。
確保你的約會帖子的YML /前端內容如下所示:
---
title: About me
featured: true
---
The content of your post...
並確保主頁布局如下所示:
<div class="about-section"> <h1>About Me</h1> <ul> {% assign featuredposts = site.posts | where:'featured','true' %} {% for post in featuredposts limit:1 %} <li> <a href="{{ post.url }}">{{ post.title }}</a> {{ post.excerpt }} </li> {% endfor %} </ul> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.