fix: pagination error when pinned posts exceed the page size (#1965)
This commit is contained in:
parent
e6b87d2811
commit
93f616b25d
1 changed files with 26 additions and 19 deletions
|
@ -5,38 +5,45 @@ refactor: true
|
||||||
|
|
||||||
{% include lang.html %}
|
{% include lang.html %}
|
||||||
|
|
||||||
{% assign pinned = site.posts | where: 'pin', 'true' %}
|
{% assign all_pinned = site.posts | where: 'pin', 'true' %}
|
||||||
{% assign default = site.posts | where_exp: 'item', 'item.pin != true and item.hidden != true' %}
|
{% assign all_normal = site.posts | where_exp: 'item', 'item.pin != true and item.hidden != true' %}
|
||||||
|
|
||||||
{% assign posts = '' | split: '' %}
|
{% assign posts = '' | split: '' %}
|
||||||
|
|
||||||
<!-- Get pinned posts -->
|
<!-- Get pinned posts on current page -->
|
||||||
|
|
||||||
{% assign offset = paginator.page | minus: 1 | times: paginator.per_page %}
|
{% assign visible_start = paginator.page | minus: 1 | times: paginator.per_page %}
|
||||||
{% assign pinned_num = pinned.size | minus: offset %}
|
{% assign visible_end = visible_start | plus: paginator.per_page %}
|
||||||
|
|
||||||
{% if pinned_num > 0 %}
|
{% if all_pinned.size > visible_start %}
|
||||||
{% for i in (offset..pinned.size) limit: pinned_num %}
|
{% if all_pinned.size > visible_end %}
|
||||||
{% assign posts = posts | push: pinned[i] %}
|
{% assign pinned_size = paginator.per_page %}
|
||||||
|
{% else %}
|
||||||
|
{% assign pinned_size = all_pinned.size | minus: visible_start %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for i in (visible_start..all_pinned.size) limit: pinned_size %}
|
||||||
|
{% assign posts = posts | push: all_pinned[i] %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% assign pinned_num = 0 %}
|
{% assign pinned_size = 0 %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Get default posts -->
|
<!-- Get normal posts on current page -->
|
||||||
|
|
||||||
{% assign default_beg = offset | minus: pinned.size %}
|
{% assign normal_size = paginator.posts | size | minus: pinned_size %}
|
||||||
|
|
||||||
{% if default_beg < 0 %}
|
{% if normal_size > 0 %}
|
||||||
{% assign default_beg = 0 %}
|
{% if pinned_size > 0 %}
|
||||||
|
{% assign normal_start = 0 %}
|
||||||
|
{% else %}
|
||||||
|
{% assign normal_start = visible_start | minus: all_pinned.size %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% assign default_num = paginator.posts | size | minus: pinned_num %}
|
{% assign normal_end = normal_start | plus: normal_size | minus: 1 %}
|
||||||
{% assign default_end = default_beg | plus: default_num | minus: 1 %}
|
|
||||||
|
|
||||||
{% if default_num > 0 %}
|
{% for i in (normal_start..normal_end) %}
|
||||||
{% for i in (default_beg..default_end) %}
|
{% assign posts = posts | push: all_normal[i] %}
|
||||||
{% assign posts = posts | push: default[i] %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue