Skip to content

Commit

Permalink
Replace site.related_posts with Liquid to display better matches ba…
Browse files Browse the repository at this point in the history
…sed on tags

- Close #554
  • Loading branch information
mmistakes committed Apr 27, 2017
1 parent 55c4f91 commit 934b052
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

### Enhancements

- Replace `site.related_posts` with Liquid to display better matches based on tags instead of the most recent posts. [#554]

### Bug Fixes

- Toggle close button on `mouseleave`. [#975](https://github.com/mmistakes/minimal-mistakes/issues/975)
Expand Down
26 changes: 26 additions & 0 deletions _includes/page__related.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% comment %}<!-- show posts by related tags when `related: true` -->{% endcomment %}
{% if page.related %}
{% assign n_posts = 0 %}
{% for post in site.posts %}
{% if post.id == page.id %}{% continue %}{% endif %}
{% for this_tag in page.tags %}
{% if post.tags contains this_tag %}
{% if n_posts == 0 %}
<div class="page__related">
{% if site.data.ui-text[site.locale].related_label %}
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
{% endif %}
<div class="grid__wrapper">
{% endif %}
{% include archive-single.html type="grid" %}
{% assign n_posts = n_posts | plus: 1 %}
{% break %}
{% endif %}
{% endfor %}
{% if n_posts > 3 %}{% break %}{% endif %}
{% endfor %}
{% if n_posts > 0 %}
</div>
</div>
{% endif %}
{% endif %}
12 changes: 1 addition & 11 deletions _layouts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,5 @@ <h4 class="page__meta-title">{{ site.data.ui-text[site.locale].meta_label }}</h4
{% endif %}
</article>

{% comment %}<!-- only show related on a post page when not disabled -->{% endcomment %}
{% if page.id and page.related and site.related_posts.size > 0 %}
<div class="page__related">
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
<div class="grid__wrapper">
{% for post in site.related_posts limit:4 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% endif %}
{% include page__related.html %}
</div>
6 changes: 5 additions & 1 deletion docs/_docs/18-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ permalink: /docs/history/
excerpt: "Change log of enhancements and bug fixes made to the theme."
sidebar:
nav: docs
last_modified_at: 2017-04-27T16:01:29-04:00
last_modified_at: 2017-04-27T16:26:51-04:00
---

## Unreleased

### Enhancements

- Replace `site.related_posts` with Liquid to display better matches based on tags instead of the most recent posts. [#554]

### Bug Fixes

- Toggle close button on `mouseleave`. [#975](https://github.com/mmistakes/minimal-mistakes/issues/975)
Expand Down
26 changes: 26 additions & 0 deletions docs/_includes/page__related.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% comment %}<!-- show posts by related tags when `related: true` -->{% endcomment %}
{% if page.related %}
{% assign n_posts = 0 %}
{% for post in site.posts %}
{% if post.id == page.id %}{% continue %}{% endif %}
{% for this_tag in page.tags %}
{% if post.tags contains this_tag %}
{% if n_posts == 0 %}
<div class="page__related">
{% if site.data.ui-text[site.locale].related_label %}
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
{% endif %}
<div class="grid__wrapper">
{% endif %}
{% include archive-single.html type="grid" %}
{% assign n_posts = n_posts | plus: 1 %}
{% break %}
{% endif %}
{% endfor %}
{% if n_posts > 3 %}{% break %}{% endif %}
{% endfor %}
{% if n_posts > 0 %}
</div>
</div>
{% endif %}
{% endif %}
12 changes: 1 addition & 11 deletions docs/_layouts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,5 @@ <h4 class="page__meta-title">{{ site.data.ui-text[site.locale].meta_label }}</h4
{% endif %}
</article>

{% comment %}<!-- only show related on a post page when not disabled -->{% endcomment %}
{% if page.id and page.related and site.related_posts.size > 0 %}
<div class="page__related">
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
<div class="grid__wrapper">
{% for post in site.related_posts limit:4 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% endif %}
{% include page__related.html %}
</div>

0 comments on commit 934b052

Please sign in to comment.