51 lines
1.9 KiB
HTML
51 lines
1.9 KiB
HTML
{% assign maxRelated = 4 %} <!-- Maximum number of related posts to output -->
|
|
{% assign minCommonTags = 1 %} <!-- Minimum number of common tags that have to match -->
|
|
{% assign maxRelatedCounter = 0 %}
|
|
|
|
{% capture related_posts %}
|
|
{% for post in site.posts %}
|
|
{% assign sameTagCount = 0 %}
|
|
{% assign commonTags = '' %}
|
|
|
|
{% for tag in post.tags %}
|
|
{% if post.url != page.url %}
|
|
{% if page.tags contains tag %}
|
|
{% assign sameTagCount = sameTagCount | plus: 1 %}
|
|
{% assign commonTags = commonTags %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% if sameTagCount >= minCommonTags %}
|
|
|
|
<!-- Post item template -->
|
|
{% include post-list-item.html %}
|
|
{% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
|
|
|
|
{% if maxRelatedCounter >= maxRelated %}
|
|
{% break %}
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% endcapture %}
|
|
|
|
<!-- Render component if there are one or more related posts -->
|
|
{% if maxRelatedCounter >= 1 %}
|
|
<div class="related-posts bg-slate-100">
|
|
<div class="related-posts__wrapper section-container">
|
|
<h1 class="related-posts__title">Keep<br>Reading</h1>
|
|
|
|
<!-- Show related posts -->
|
|
<ul class="post-list">
|
|
{{ related_posts }}
|
|
</ul>
|
|
|
|
<!-- Decorative arrows -->
|
|
<svg class="related-posts__arrow svg-icon"><use xlink:href="{{ '/assets/images/icons/icon-sprite.svg#arrow-right' | relative_url }}"></use></svg>
|
|
<svg class="related-posts__arrow svg-icon"><use xlink:href="{{ '/assets/images/icons/icon-sprite.svg#arrow-right' | relative_url }}"></use></svg>
|
|
<svg class="related-posts__arrow svg-icon"><use xlink:href="{{ '/assets/images/icons/icon-sprite.svg#arrow-right' | relative_url }}"></use></svg>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|