简体   繁体   English

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

[英]How to display an excerpt from a single post using Jekyll

I'm creating a blog site using Jekyll and I want to add a short "about" section on the homepage. 我正在使用Jekyll创建一个博客网站,我想在主页上添加一个简短的“关于”部分。 Instead of creating a separate paragraph, I'm going to create an "About Me" post (about-me.md) and insert an excerpt from that post on the homepage in its place (beneath it will be a link to read the rest of the article). 而不是创建一个单独的段落,我将创建一个“关于我”帖子(about-me.md)并在主页上插入该帖子的摘录(在其下方将是一个阅读其余内容的链接)该文章)。

The only information I can find online is about the "latest posts" section utilizing the 'for' loop to show the 5 (or more) recent posts. 我在网上找到的唯一信息是关于“最新帖子”部分,利用“for”循环显示最近的5个(或更多)帖子。 I can't find anything else in the Jekyll documentation that explains how to display an excerpt from one specific post. 我在Jekyll文档中找不到任何其他内容来解释如何显示某个特定帖子的摘录。

I've tried changing 我试过改变

{{ post.excerpt }}

to

{{ about-me.excerpt }}

but to no avail. 但无济于事。

Below is the 'recent posts' implementation: 以下是“近期帖子”的实施情况:

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

This works to display the recent posts including an excerpt. 这可以显示最近的帖子,包括摘录。 I need to only display the excerpt from the 'about-me.md' post immediately under the title. 我只需要在标题下面的'about-me.md'帖子中显示摘录。

Make sure the YML/front matter of your about-me post looks like this: 确保你的约会帖子的YML /前端内容如下所示:

---
title: About me
featured: true
---

The content of your post...

And make sure the home page layout looks like this: 并确保主页布局如下所示:

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

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