Jekyll paginate:偏移所有页面,而不仅仅是第一页
我在使用Jekyll(使用液体模板语言)、插件Jekyll paginate:偏移所有页面,而不仅仅是第一页,jekyll,liquid,jekyll-extensions,jekyll-paginator,Jekyll,Liquid,Jekyll Extensions,Jekyll Paginator,我在使用Jekyll(使用液体模板语言)、插件Jekyll-paginate-v2和offset时遇到了一个问题 问题:我的博客上有一个特色部分,总是显示最近的文章。其他帖子如下所示,使用paginate每页10篇 我试图简单地在paginator.posts offset:1%}中使用{%for post来显示它们,但这在两个方面存在缺陷: 它每页只显示9篇文章,而不是10篇 它偏移了每页上的第一篇文章,所以第一、第十、第二十等文章都被隐藏了,这不是我想要的 我试图实现的目标:一个循环,它
Jekyll-paginate-v2
和offset
时遇到了一个问题
问题:我的博客上有一个特色部分,总是显示最近的文章。其他帖子如下所示,使用paginate每页10篇
我试图简单地在paginator.posts offset:1%}中使用{%for post来显示它们,但这在两个方面存在缺陷:
- 它每页只显示9篇文章,而不是10篇
- 它偏移了每页上的第一篇文章,所以第一、第十、第二十等文章都被隐藏了,这不是我想要的
我试图实现的目标:一个循环,它总是忽略索引0处的帖子,并以正常方式显示所有其他内容
我只是使用了offset
错误,还是这是jekyll-paginate-v2
中的错误
现在我已经通过以下方式“修复”了它,但它并不理想,因为第一页只显示了9篇文章:
<div class="articles-showcase row post-list">
{% assign featuredpost = site.posts.first %}
{% for post in paginator.posts %}
{% if post == featuredpost %}
{% continue %}
{% else %}
<!-- Article Card -->
<div class="article-detail-box col-lg-6 col-md-6 col-sm-12 card-article-div" data-cat="{{post.category | join: ','}}">
<div class="card card-article box-shadow h-100">
<a href="{{ site.baseurl }}{{post.url}}" class="card-article-linker" title="{{post.title}}"></a>
<div class="img-div text-center post-card-header bg-gray">
<img src="{{ site.baseurl }}{{post.image}}" alt="{{post.title}}">
</div>
<div class="card-article-body">
<p class="author-name">{{post.author}} | {{ post.date | date: '%B %d, %Y' }}</p>
<a href="{{site.baseurl}}{{post.url}}">
<h5>{{post.title}}</h5>
</a>
<div class="article-description">{{post.content}}</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{%assign featuredpost=site.posts.first%}
{paginator.posts%中的post为%s}
{%if post==featuredpost%}
{%continue%}
{%else%}
{{post.content}
{%endif%}
{%endfor%}
我已经拼凑出一个有缺陷的解决方案,我正在使用它,直到出现更好的解决方案。我现在就在这里分享:
<div class="articles-showcase row post-list">
{% if paginator.page == 1 %}
{% for post in site.posts limit:11 %}
{% if post == featuredpost %}
{% continue %}
{% else %}
<!-- Article Card -->
<div class="article-detail-box col-lg-6 col-md-6 col-sm-12 card-article-div" data-cat="{{post.category | join: ','}}">
<div class="card card-article box-shadow h-100">
<a href="{{ site.baseurl }}{{post.url}}" class="card-article-linker" title="{{post.title}}"></a>
<div class="img-div text-center post-card-header bg-gray">
<img src="{{ site.baseurl }}{{post.image}}" alt="{{post.title}}">
</div>
<div class="card-article-body">
<p class="author-name">{{post.author}} | {{ post.date | date: '%B %d, %Y' }}</p>
<a href="{{site.baseurl}}{{post.url}}">
<h5>{{post.title}}</h5>
</a>
<div class="article-description">{{post.content}}</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
{% endif %}
{% if paginator.page > 1 %}
{% for post in paginator.posts %}
<!-- Article Card -->
<div class="article-detail-box col-lg-6 col-md-6 col-sm-12 card-article-div" data-cat="{{post.category | join: ','}}">
<div class="card card-article box-shadow h-100">
<a href="{{ site.baseurl }}{{post.url}}" class="card-article-linker" title="{{post.title}}"></a>
<div class="img-div text-center post-card-header bg-gray">
<img src="{{ site.baseurl }}{{post.image}}" alt="{{post.title}}">
</div>
<div class="card-article-body">
<p class="author-name">{{post.author}} | {{ post.date | date: '%B %d, %Y' }}</p>
<a href="{{site.baseurl}}{{post.url}}">
<h5>{{post.title}}</h5>
</a>
<div class="article-description">{{post.content}}</div>
</div>
</div>
</div>
{% endfor %}
{% endif %}
</div>
{%if paginator.page==1%}
{站点中帖子的百分比。帖子限制:11%}
{%if post==featuredpost%}
{%continue%}
{%else%}
{{post.content}
{%endif%}
{%endfor%}
{%endif%}
{%如果paginator.page>1%}
{paginator.posts%中的post为%s}
{{post.content}
{%endfor%}
{%endif%}
它的主要问题是第二页再次显示了第一页的最后一篇文章。然而,对我来说,这比在第一页只显示9篇文章要好。任何更好的解决方案都将不胜感激 作为一个快速解决方案,您应该能够手动将front matter属性添加到最新的帖子中:
---
layout: page
pagination:
enabled: false
---
否则,您必须排除paginator-v2插件并编写自己的分页逻辑,或者在\u plugins
目录中扩展插件,以便发送到paginate插件的POST数据已经排除了第一个(实际上是最后一个,因为随后将进行反向排序)帖子。我向jekyll-paginate-v2开发人员提出了这个问题,现在问题已经解决了:我确实想到了,但手动将最新帖子设置为特色正是我想要避免的。我希望它能自动发布最新的帖子,这样帖子作者就不用担心一件事了(而且可能会搞砸)。我会考虑修改插件或制作自己的插件。问题是我是python/JS开发人员,不是ruby:)