2019-10-21 17:12:36 +03:00
|
|
|
<!--
|
|
|
|
The related posts of current post.
|
|
|
|
Placed in the bottom of every single post.
|
2020-01-02 16:17:49 +03:00
|
|
|
v2.0
|
|
|
|
https://github.com/cotes2020/jekyll-theme-chirpy
|
2019-10-21 17:12:36 +03:00
|
|
|
© 2019 Cotes Chung
|
|
|
|
Published under the MIT License
|
|
|
|
-->
|
|
|
|
|
|
|
|
{% assign MAX_SIZE = 3 %}
|
|
|
|
{% assign TAG_SCORE = 1 %}
|
|
|
|
{% assign CATEGORY_SCORE = 0.5 %}
|
|
|
|
|
|
|
|
{% assign score_list = "" | split: "" %}
|
|
|
|
{% assign post_index = 0 %}
|
|
|
|
|
|
|
|
{% for post in site.posts %}
|
|
|
|
{% if post.url != page.url %}
|
|
|
|
{% assign score = 0 %}
|
|
|
|
|
|
|
|
{% for tag in post.tags %}
|
|
|
|
{% if page.tags contains tag %}
|
|
|
|
{% assign score = score | plus: TAG_SCORE %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for category in post.categories %}
|
|
|
|
{% if page.categories contains category %}
|
|
|
|
{% assign score = score | plus: CATEGORY_SCORE %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% if score > 0 %}
|
|
|
|
{% capture score_item %}{{ score }}:{{ post_index }}{% endcapture %}
|
|
|
|
{% assign score_list = score_list | push: score_item %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
{% assign post_index = post_index | plus: 1 %}
|
|
|
|
{% endfor %}
|
|
|
|
|
2019-10-26 08:21:58 +03:00
|
|
|
{% if score_list.size > 0 %}
|
2019-10-21 17:12:36 +03:00
|
|
|
{% assign score_list = score_list | sort | reverse %}
|
|
|
|
{% assign count = 0 %}
|
2020-01-02 19:37:56 +03:00
|
|
|
<div id="related-posts" class="mt-4 mb-2 mb-sm-4 pb-2">
|
2020-02-16 22:01:48 +03:00
|
|
|
<h3 class="pt-2 mt-1 mb-4 ml-1" data-toc-skip>{{ site.data.label.post.relate_posts }}</h3>
|
2019-10-21 17:12:36 +03:00
|
|
|
<div class="card-deck mb-4">
|
|
|
|
{% for score_item in score_list %}
|
|
|
|
{% assign data = score_item | split: ":" %}
|
|
|
|
{% assign index = data[1] | plus: 0 %}
|
|
|
|
{% assign post = site.posts[index] %}
|
2019-10-26 08:21:58 +03:00
|
|
|
<div class="card">
|
2020-02-02 22:26:20 +03:00
|
|
|
<a href="{{ post.url | relative_url }}">
|
2019-10-21 17:12:36 +03:00
|
|
|
<div class="card-body">
|
2019-10-26 08:21:58 +03:00
|
|
|
<span class="timeago small">
|
2020-02-22 02:16:58 +03:00
|
|
|
{{ post.date | date: site.data.date_format.post }}
|
2019-12-31 18:17:27 +03:00
|
|
|
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
|
2019-10-21 17:12:36 +03:00
|
|
|
</span>
|
2020-01-02 15:58:00 +03:00
|
|
|
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
|
2019-10-21 17:12:36 +03:00
|
|
|
<div class="text-muted small">
|
2020-05-05 19:39:28 +03:00
|
|
|
{% assign content = post.content %}
|
|
|
|
{% include no-linenos.html %}
|
|
|
|
<p>{{ content | markdownify | strip_html | truncate: 200 | replace: '&', '&' }}</p>
|
2019-10-21 17:12:36 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
{% assign count = count | plus: 1 %}
|
|
|
|
{% if count >= MAX_SIZE %}
|
|
|
|
{% break %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2019-10-26 08:21:58 +03:00
|
|
|
</div> <!-- .card-deck -->
|
2019-10-21 17:12:36 +03:00
|
|
|
</div>
|
2019-10-26 08:21:58 +03:00
|
|
|
{% endif %}
|