Skip to content

Commit e7149cc

Browse files
committed
Add related writings under post
1 parent e120861 commit e7149cc

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

_layouts/post.html

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,28 @@ <h1 class="post__title">{{ title }}</h1>
1616
</div>
1717
<div class="post__content">{{ content }}</div>
1818
<footer class="post__footer">
19-
Read more articles about {% for category in categories %}<a
20-
href="{{site.baseurl}}/categories/#{{category|slugify}}"
21-
>{{ category }}</a
22-
>{% if forloop.last != true %}, {% endif %}{% endfor %}.
19+
{% assign first_category = categories[0] %} {% assign all_related_posts =
20+
collections.posts %} {% if all_related_posts.size > 0 %}
21+
<ul class="post__related">
22+
<div><strong>Related Writings:</strong></div>
23+
{% assign count = 0 %} {% for post in all_related_posts %} {% assign
24+
has_category = false %} {% for post_category in post.data.categories %} {%
25+
if post_category == first_category %} {% assign has_category = true %} {%
26+
endif %} {% endfor %} {% if has_category and post.url != page.url and
27+
count < 5 %}
28+
<li class="post__related-item">
29+
<a href="{{ site.baseurl }}{{ post.url }}">{{ post.data.title }}</a>
30+
</li>
31+
{% assign count = count | plus: 1 %} {% endif %} {% endfor %}
32+
</ul>
33+
{% else %}
34+
<p>
35+
Read more about {% for category in categories %}<a
36+
href="{{site.baseurl}}/categories/#{{category|slugify}}"
37+
>{{ category }}</a
38+
>{% if forloop.last != true %}, {% endif %}{% endfor %}.
39+
</p>
40+
{% endif %}
2341
</footer>
2442
</article>
2543

assets/css/posts.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@
103103
font-size: 15px;
104104
}
105105

106+
.post__related {
107+
list-style-type: none;
108+
padding: 0;
109+
margin: 0;
110+
}
111+
112+
.post__related-item {
113+
position: relative;
114+
padding-left: 1.5rem;
115+
}
116+
.post__related-item:before {
117+
content: "→";
118+
position: absolute;
119+
left: 0.4rem;
120+
font-weight: bold;
121+
}
106122
.video-fluid-wrapper {
107123
position: relative;
108124
padding-bottom: 56.25%; /* 16:9 */

worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var staticAssetsCacheName = "StaticAssetsList",
22
imageAssetsCacheName = "ImgStaticList",
3-
version = "v3:1:";
3+
version = "v3:1:3";
44

55
var staticPrimaryAssets = ["/", "/index.css"];
66

0 commit comments

Comments
 (0)