Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added related posts section #1168

Merged
merged 8 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions _includes/related_posts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% assign maxRelated = 5 %}
{% assign minCommonTags = 1 %}
alshedivat marked this conversation as resolved.
Show resolved Hide resolved
{% assign maxRelatedCounter = 0 %}
{% assign haveRelatedPosts = false %}

{% for post in site.posts %}
{% assign sameTagCount = 0 %}

{% for tag in post.tags %}
{% if post.url != page.url %}
{% if page.tags contains tag %}
{% assign sameTagCount = sameTagCount | plus: 1 %}
{% endif %}
{% endif %}
{% endfor %}

{% if sameTagCount >= minCommonTags %}
{% unless haveRelatedPosts %}
{% assign haveRelatedPosts = true %}

<br>
<hr>
<br>
<ul class="list-disc pl-8"></ul>

<!-- Adds related posts to the end of an article -->
<h2 class="text-3xl font-semibold mb-4 mt-12">Enjoy Reading This Article?</h2>
<p class="mb-2">Here are some more articles you might like to read next:</p>
{% endunless %}

<li class="my-2">
<a class="text-pink-700 underline font-semibold hover:text-pink-800" href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
</li>

{% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}

{% if maxRelatedCounter >= maxRelated %}
{% break %}
{% endif %}

{% endif %}
{% endfor %}

{% if maxRelatedCounter > 0 %}
</ul>
{% endif %}
4 changes: 4 additions & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ <h1 class="post-title">{{ page.title }}</h1>
{{ content }}
</article>

{%- if page.related_posts -%}
{% include related_posts.html %}
{%- endif %}

{%- if site.disqus_shortname and page.disqus_comments -%}
{% include disqus.html %}
{%- endif %}
Expand Down
1 change: 1 addition & 0 deletions _posts/2015-03-15-formatting-and-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ date: 2015-03-15 16:40:16
description: march & april, looking forward to summer
tags: formatting links
categories: sample-posts
related_posts: true
---
Jean shorts raw denim Vice normcore, art party High Life PBR skateboard stumptown vinyl kitsch. Four loko meh 8-bit, tousled banh mi tilde forage Schlitz dreamcatcher twee 3 wolf moon. Chambray asymmetrical paleo salvia, sartorial umami four loko master cleanse drinking vinegar brunch. <a href="https://www.pinterest.com">Pinterest</a> DIY authentic Schlitz, hoodie Intelligentsia butcher trust fund brunch shabby chic Kickstarter forage flexitarian. Direct trade <a href="https://en.wikipedia.org/wiki/Cold-pressed_juice">cold-pressed</a> meggings stumptown plaid, pop-up taxidermy. Hoodie XOXO fingerstache scenester Echo Park. Plaid ugh Wes Anderson, freegan pug selvage fanny pack leggings pickled food truck DIY irony Banksy.

Expand Down
1 change: 1 addition & 0 deletions _posts/2015-05-15-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ date: 2015-05-15 21:01:00
description: this is what included images could look like
tags: formatting images
categories: sample-posts
related_posts: true
---
This is an example post with image galleries.

Expand Down
1 change: 1 addition & 0 deletions _posts/2015-07-15-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ date: 2015-07-15 15:09:00
description: an example of a blog post with some code
tags: formatting code
categories: sample-posts
related_posts: true
---
This theme implements a built-in Jekyll feature, the use of Rouge, for syntax highlighting.
It supports more than 100 languages.
Expand Down
1 change: 1 addition & 0 deletions _posts/2015-10-20-disqus-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ date: 2015-10-20 11:59:00-0400
description: an example of a blog post with disqus comments
categories: sample-posts external-services
disqus_comments: true
related_posts: true
---
This post shows how to add DISQUS comments.
1 change: 1 addition & 0 deletions _posts/2015-10-20-math.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ date: 2015-10-20 11:12:00-0400
description: an example of a blog post with some math
tags: formatting math
categories: sample-posts
related_posts: true
---
This theme supports rendering beautiful math in inline and display modes using [MathJax 3](https://www.mathjax.org/) engine. You just need to surround your math expression with `$$`, like `$$ E = mc^2 $$`. If you leave it inside a paragraph, it will produce an inline expression, just like $$ E = mc^2 $$.

Expand Down
1 change: 1 addition & 0 deletions _posts/2020-09-28-github-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: a post with github metadata
date: 2020-09-28 21:01:00
description: a quick run down on accessing github metadata.
categories: sample-posts external-services
related_posts: true
---

A sample blog page that demonstrates the accessing of github meta data.
Expand Down
1 change: 1 addition & 0 deletions _posts/2020-09-28-twitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ date: 2020-09-28 11:12:00-0400
description: an example of a blog post with twitter
tags: formatting
categories: sample-posts external-services
related_posts: true
---
A sample blog page that demonstrates the inclusion of Tweets/Timelines/etc.

Expand Down
1 change: 1 addition & 0 deletions _posts/2021-07-04-diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: post
title: a post with diagrams
date: 2021-07-04 17:39:00
description: an example of a blog post with diagrams
related_posts: true
---

This theme supports generating various diagrams from a text description using [jekyll-diagrams](https://github.com/zhustec/jekyll-diagrams){:target="\_blank"} plugin.
Expand Down
1 change: 1 addition & 0 deletions _posts/2022-12-10-giscus-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ date: 2022-12-10 11:59:00-0400
description: an example of a blog post with giscus comments
categories: sample-posts external-services
giscus_comments: true
related_posts: true
---
This post shows how to add GISCUS comments.