【问题标题】:Jekyll paginator killed post.excerptJekyll 分页器杀死了 post.excerpt
【发布时间】:2023-03-13 03:05:02
【问题描述】:

我在 Jekyll 生成的网站上使用分页器时遇到了一个奇怪的行为。 我曾经将最后 3 个帖子的列表创建为

<ul class="post-list">
    {% for post in site.posts limit:3 %}
      <li>
        <span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>

        <h2>
          <a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
        </h2>
        <p>{{ post.excerpt }}</p>
      </li>
    {% endfor %}
</ul>

当我在 Jekyll 中激活分页器并循环页面时

{% for post in site.posts %}
<div class="post-preview">
    <a href="{{ post.url | prepend: site.baseurl }}">
        <h2 class="post-title">{{ post.title }}</h2>
        {% if post.subtitle %}
        <h3 class="post-subtitle">
            {{ post.subtitle }}
        </h3>
        <p>{{ post.excerpt }}</p>
        {% endif %}
    </a>
    <p class="post-meta">Posted by {% if post.author %}{{ post.author }}{% else %}{{ site.title }}{% endif %} on {{ post.date | date: "%B %-d, %Y" }}</p>
</div>
<hr>
{% endfor %} 

post.excerpt 变为空。我尝试了标准行为和技巧。

_config.yml 中的构建设置如下:

# Build settings
gems: [jekyll-sitemap]
markdown: kramdown
highlighter: rouge
permalink: pretty
paginate: 5
paginate_path: "/archives/page/:num"

谢谢

【问题讨论】:

    标签: pagination jekyll


    【解决方案1】:

    您已将{{ post.excerpt }} 表达式放入条件语句中。

    {% if post.subtitle %}
      <h3 class="post-subtitle">{{ post.subtitle }}</h3>
      <p>{{ post.excerpt }}</p>
    {% endif %}
    

    所以,没有字幕,没有摘录!

    这样更好:

    {% if post.subtitle %}
      <h3 class="post-subtitle">{{ post.subtitle }}</h3>
    {% endif %}
    <p>{{ post.excerpt }}</p>
    

    为了呈现分页帖子,您必须循环输入 paginator.posts see documentation

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 1970-01-01
      • 2014-11-06
      • 2015-01-14
      • 1970-01-01
      • 2012-01-03
      • 2017-06-06
      • 2021-09-06
      • 2018-04-26
      相关资源
      最近更新 更多