title: Filter site.related_posts in Jekyll
body: <p>I am very new to Jekyll and Ruby (yet, <em>very</em> excited).</p>
  
  <p>Without using a plugin, I am trying to find a way to filter the <code>site.related_posts</code>.</p>
  
  <p>For example, I am reading the post with title <code>Foo</code> and categories <code>A, B</code>.</p>
  
  <p>The site contains in total 3 posts:</p>
  
  <ol>
  <li><code>Foo</code> (Categories: A, B)</li>
  <li><code>Bar</code> (Categories: A, C, D)</li>
  <li><code>Zoo</code> (Categories: B, F)</li>
  </ol>
  
  <p>By the default, in Jekyll we do this:</p>
  
  <blockquote>
    <p>{% for post in site.related_posts limit:5 %}<br>
      {% endfor %}</p>
  </blockquote>
  
  <p>However, the above code returns all the (3) posts.</p>
  
  <p>A post contains many categories, so categories should be an array.</p>
  
  <p>How can I modify the code and return only those whose categories intersect with the current post's categories?</p>
  
  <p>(In this example, I would like the code to return only <code>Foo</code> and <code>Zoo</code>.)</p>