poole / lanyon

A content-first, sliding sidebar theme for Jekyll.
http://lanyon.getpoole.com
Other
3.25k stars 2.95k forks source link

Relate posts in a better way #251

Open hash-ir opened 4 years ago

hash-ir commented 4 years ago

In v1.1.0, the Related Posts snippet in post.html lists the three posts, not in relation to the opened post. I thought of including a tag in the front matter e.g tag: Computer Science or tag: Fiction and then list the posts accordingly. How do I change the following code to incorporate this?

{% if site.related_posts.size >= 1 %}
<div class="related">
  <h2>Related posts</h2>
  <ul class="related-posts">
    {% for post in site.related_posts limit:3 %}
      <li>
        <h3>
          <a href="{{ site.baseurl }}{{ post.url }}">
            {{ post.title }}
            <small>{{ post.date | date_to_string }}</small>
          </a>
        </h3>
      </li>
    {% endfor %}
  </ul>
</div>
{% endif %}

Apologies if this is something very basic to ask. I don't have any web design experience but I am having my fun modifying the theme.

JeremyRubin commented 3 years ago

hi @hash-ir -- you most likely want to use the jekyll LSI to get semantically related posts. Look into using it https://frankindev.com/2019/11/21/enable-related-posts-with-lsi/