Skip to content

Commit

Permalink
Exclude hidden posts from page__related, fix #4653
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Apr 23, 2024
1 parent 7746db6 commit 60b9565
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- "You may also enjoy" no longer recommends hidden posts. [#4653](https://github.com/mmistakes/minimal-mistakes/issues/4653)

### Enhancements

- Add Ukrainian translations. [#4273](https://github.com/mmistakes/minimal-mistakes/pull/4273)
Expand Down
15 changes: 15 additions & 0 deletions _includes/page__related.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="page__related">
{% include before-related.html %}
<h2 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h2>
<div class="grid__wrapper">
{% assign count = 0 %}
{% assign limit = include.limit | default: 4 %}
{% for post in include.posts %}
{% if post.hidden %}{% continue %}{% endif %}
{% if post.id == page.id %}{% continue %}{% endif %}
{% if count >= limit %}{% break %}{% endif %}
{% assign count = count | plus: 1 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
23 changes: 2 additions & 21 deletions _layouts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,9 @@ <h4 class="page__meta-title">{{ site.data.ui-text[site.locale].meta_label }}</h4

{% comment %}<!-- only show related on a post page when `related: true` -->{% endcomment %}
{% if page.id and page.related and site.related_posts.size > 0 %}
<div class="page__related">
{% include before-related.html %}
<h2 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h2>
<div class="grid__wrapper">
{% for post in site.related_posts limit:4 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% include page__related.html posts=site.related_posts %}
{% comment %}<!-- otherwise show recent posts if no related when `related: true` -->{% endcomment %}
{% elsif page.id and page.related %}
<div class="page__related">
{% include before-related.html %}
<h2 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h2>
<div class="grid__wrapper">
{% for post in site.posts limit:4 %}
{% if post.id == page.id %}
{% continue %}
{% endif %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% include page__related.html posts=site.posts %}
{% endif %}
</div>
6 changes: 5 additions & 1 deletion docs/_docs/18-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ permalink: "/docs/history/"
excerpt: Change log of enhancements and bug fixes made to the theme.
sidebar:
nav: docs
last_modified_at: '2024-04-23T12:08:54+08:00'
last_modified_at: '2024-04-23T12:18:03+08:00'
toc: false
---

Expand All @@ -17,6 +17,10 @@ toc: false
{% raw %}
## Unreleased

### Bug Fixes

- "You may also enjoy" no longer recommends hidden posts. [#4653](https://github.com/mmistakes/minimal-mistakes/issues/4653)

### Enhancements

- Add Ukrainian translations. [#4273](https://github.com/mmistakes/minimal-mistakes/pull/4273)
Expand Down

0 comments on commit 60b9565

Please sign in to comment.