-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelated-posts.html
More file actions
54 lines (44 loc) · 2 KB
/
related-posts.html
File metadata and controls
54 lines (44 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!-- Related Posts
================================================== -->
<div class="{% unless page.categories == empty %} related-posts {% endunless %}">
{% unless page.categories == empty %}
<h2 class="text-center mb-4">Explore more like this</h2>
{% endunless %}
<div class="d-flex justify-content-center align-items-center">
<!-- Categories -->
{% assign sortedCategories = page.categories | sort %}
{% for category in sortedCategories %}
<a class="smoothscroll badge badge-primary text-capitalize" href="{{site.baseurl}}/categories#{{ category | replace: " ","-" }}">{{ category }}</a>
{% endfor %}
<!-- Tags -->
{% assign sortedTags = page.tags | sort %}
{% for tag in sortedTags %}
<a class="smoothscroll badge badge-primary text-capitalize" href="{{site.baseurl}}/tags#{{ tag | replace: " ","-" }}">{{ tag }}</a>
{% endfor %}
</div>
{% assign maxRelated = 3 %}
{% assign minCommonTags = 1 %}
{% assign maxRelatedCounter = 0 %}
<div class="blog-grid-container">
{% for post in site.posts %}
{% assign sameTagCount = 0 %}
{% assign commonTags = '' %}
{% for category in post.categories %}
{% if post.url != page.url %}
{% if page.categories contains category %}
{% assign sameTagCount = sameTagCount | plus: 1 %}
{% capture tagmarkup %} {{ category }} {% endcapture %}
{% assign commonTags = commonTags | append: tagmarkup %}
{% endif %}
{% endif %}
{% endfor %}
{% if sameTagCount >= minCommonTags %}
{% include postbox.html %}
{% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
{% if maxRelatedCounter >= maxRelated %}
{% break %}
{% endif %}
{% endif %}
{% endfor %}
</div>
</div>