1
votes

I have got a bizarre behaviour using paginator on a Jekyll generated website. I used to create the list of the last 3 posts as

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

As soon as I activated the paginator in Jekyll and cycled pages as

{% 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 becomes empty. I tried both with the standard behaviour and with the trick.

Build Settings in _config.yml are as such:

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

Thank you

1

1 Answers

1
votes

You've put {{ post.excerpt }} expression in a conditional statement.

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

So, no subtitle, no excerpt !

This is better :

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

In order to render paginated posts you must loop in paginator.posts see documentation