如何使用 Jekyll 显示单个 post 的摘录

How to display an excerpt from a single post using Jekyll

我正在使用 Jekyll 创建一个博客站点,我想在主页上添加一个简短的 "about" 部分。我不会创建一个单独的段落,而是要创建一个 "About Me" post (about-me.md) 并在主页上插入一段 post 的摘录(在它下面将是一个 link 以阅读文章的其余部分)。

我在网上能找到的唯一信息是关于 "latest posts" 部分利用 'for' 循环显示 5(或更多)最近的 post。我在 Jekyll 文档中找不到任何其他内容来解释如何显示一个特定 post.

的摘录

我试过改变

{{ post.excerpt }}

{{ about-me.excerpt }}

但无济于事。

下面是 'recent posts' 实现:

<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>

这可以显示最近的 posts,包括摘录。我只需要在标题正下方显示 'about-me.md' post 的摘录。

确保你的 about-me post 的 YML/front 事情看起来像这样:

---
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>