【问题标题】:How to display an excerpt from a single post using Jekyll如何使用 Jekyll 显示单个帖子的摘录
【发布时间】:2019-06-10 12:29:27
【问题描述】:

我正在使用 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”帖子的摘录。

【问题讨论】:

    标签: html jekyll


    【解决方案1】:

    确保你的 about-me 帖子的 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>

    【讨论】:

      猜你喜欢
      • 2013-10-23
      • 2013-03-07
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      相关资源
      最近更新 更多