Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Show 4 latest posts when site.related_posts is nil
Browse files Browse the repository at this point in the history
`site.related_posts` should return an array of latest posts when no related ones are found due to `lsi` being disabled (GitHub Page's doesn't support it).

This works around that bug by showing the 4 latest posts to populate the "You May Also Enjoy" module when enabled with `related: true`.

Fixes mmistakes#554
Related: mmistakes#978 mmistakes#1022
  • Loading branch information
makaroniame committed Sep 5, 2017
1 parent 543bc57 commit 35b3452
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Improve Chinese `date_label` and `minute_read` translations in `ui-text.yml`. [#1205](https://github.com/mmistakes/minimal-mistakes/pull/1205) [#1211](https://github.com/mmistakes/minimal-mistakes/pull/1211)
- Add note to Quick-Start Guide about GitHub Pages hosting alternatives that allow 3rd party gem themes and Jekyll plugins.
- Add note to configuration documentation about Cloudflare minification as an alternative to `layout: compress`. [#1217](https://github.com/mmistakes/minimal-mistakes/pull/1217)
- Show 4 latest posts in "You May Also Enjoy" module when `related: true` and no related posts are found due to `lsi` ([latent semantic indexing](https://en.wikipedia.org/wiki/Latent_semantic_analysis#Latent_semantic_indexing)) being disabled on GitHub Pages. [#554](https://github.com/mmistakes/minimal-mistakes/issues/554)

### Bug Fixes

Expand Down
12 changes: 11 additions & 1 deletion _layouts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <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 %}
{% 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">
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
Expand All @@ -70,5 +70,15 @@ <h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label
{% endfor %}
</div>
</div>
{% comment %}<!-- otherwise show recent posts if no related when `related: true` -->{% endcomment %}
{% elsif page.id and page.related %}
<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.posts limit:4 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% endif %}
</div>
3 changes: 2 additions & 1 deletion docs/_docs/18-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ permalink: /docs/history/
excerpt: "Change log of enhancements and bug fixes made to the theme."
sidebar:
nav: docs
last_modified_at: 2017-09-05T12:07:50-04:00
last_modified_at: 2017-09-05T12:58:56-04:00
---

## Unreleased
Expand All @@ -20,6 +20,7 @@ last_modified_at: 2017-09-05T12:07:50-04:00
- Improve Chinese `date_label` and `minute_read` translations in `ui-text.yml`. [#1205](https://github.com/mmistakes/minimal-mistakes/pull/1205) [#1211](https://github.com/mmistakes/minimal-mistakes/pull/1211)
- Add note to Quick-Start Guide about GitHub Pages hosting alternatives that allow 3rd party gem themes and Jekyll plugins.
- Add note to configuration documentation about Cloudflare minification as an alternative to `layout: compress`. [#1217](https://github.com/mmistakes/minimal-mistakes/pull/1217)
- Show 4 latest posts in "You May Also Enjoy" module when `related: true` and no related posts are found due to `lsi` ([latent semantic indexing](https://en.wikipedia.org/wiki/Latent_semantic_analysis#Latent_semantic_indexing)) being disabled on GitHub Pages. [#554](https://github.com/mmistakes/minimal-mistakes/issues/554)

### Bug Fixes

Expand Down
12 changes: 11 additions & 1 deletion docs/_layouts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <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 %}
{% 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">
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
Expand All @@ -70,5 +70,15 @@ <h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label
{% endfor %}
</div>
</div>
{% comment %}<!-- otherwise show recent posts if no related when `related: true` -->{% endcomment %}
{% elsif page.id and page.related %}
<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.posts limit:4 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% endif %}
</div>

0 comments on commit 35b3452

Please sign in to comment.