1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Super feature: Pinned posts.

This commit is contained in:
Cotes Chung
2020-06-06 12:45:33 +08:00
parent d1963af964
commit 34d54f9349
7 changed files with 75 additions and 9 deletions

View File

@@ -7,12 +7,59 @@ layout: page
# MIT Licensed
---
{% assign pinned = site.posts | where_exp: "item", "item.pin == true" %}
{% assign default = site.posts | where_exp: "item", "item.pin == nil " %}
{% assign posts = "" | split: "" %}
<!-- Get pinned posts -->
{% assign offset = paginator.page | minus: 1 | times: paginator.per_page %}
{% assign pinned_num = pinned.size | minus: offset %}
{% if pinned_num > 0 %}
{% for i in (offset..pinned.size) limit: pinned_num %}
{% assign posts = posts | push: pinned[i] %}
{% endfor %}
{% else %}
{% assign pinned_num = 0 %}
{% endif %}
<!-- Get defualt posts -->
{% assign default_beg = offset | minus: pinned.size %}
{% if default_beg < 0 %}
{% assign default_beg = 0 %}
{% endif %}
{% assign default_num = paginator.posts | size | minus: pinned_num %}
{% assign default_end = default_beg | plus: default_num | minus: 1 %}
{% if default_num > 0 %}
{% for i in (default_beg..default_end) %}
{% assign posts = posts | push: default[i] %}
{% endfor %}
{% endif %}
<div id="post-list">
{% for post in paginator.posts %}
{% for post in posts %}
<div class="post-preview">
<h1>
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
</h1>
<div class="d-flex justify-content-between align-items-center pr-2">
<h1><a href="{{ post.url | relative_url }}">{{ post.title }}</a></h1>
{% if post.pin %}
<i class="fas fa-thumbtack fa-fw fa-sm text-muted pinned" data-toggle="tooltip" data-placement="top"
title="Pinned"></i>
{% endif %}
</div>
<div class="post-content">
<p>
{% assign _content = post.content %}
@@ -38,7 +85,9 @@ layout: page
{% endif %}
</div>
</div> <!-- .post-review -->
{% endfor %}
{% endfor %}
</div> <!-- #post-list -->
{% if paginator.total_pages > 0 %}