Exclude hidden posts from page__related, fix #4653

This commit is contained in:
iBug 2024-04-23 12:18:07 +08:00
parent 7746db6f7e
commit 60b9565277
4 changed files with 26 additions and 22 deletions

View File

@ -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)

View File

@ -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>

View File

@ -70,28 +70,9 @@ layout: default
{% 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>

View File

@ -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
---
@ -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)