I posted Added Suggested Posts on Monday, 14 September, 2015

I started writing about PNWPHP but got distracted and added "Suggested Reading" to my posts instead.

Post jekyll site

Added Suggested Posts

This weekend I attended PNWPHP. It was great. Instead of writing about that, I started looking up how to manage Related Posts in Jekyll. There are built-in options to do that, but they never satisfied me. I found Wenli Zhang’s post Jekyll Related Posts without Plugin and understood a little better.

Okay, no. Not really. But that post led me to related_posts-jekyll-plugin and this fork by jumanji27 which is friendler for current Jekyll releases.

Since it’s a little more fiddly than a regular plugin, I hand-copied the code into a file _plugins/related-posts.rb and added a nice little "Suggested Posts" footer to the post template.

<article itemscope itemtype="http://schema.org/BlogPosting">
  ...
  <footer>
    <h3>Suggested Posts</h3>
    <p>
      {% for post in site.related_posts limit:5 %}
      <a href="{{ post.url }}" class="post-link">{{ post.title }}</a>{% unless forloop.last %}, {% endunless %}
      {% endfor %}
    </p>
  </footer>
</article>

I limited it to five related posts. Some posts will have a hundred related posts due to the way I imported content from my other sites.

Incidentally, I think this plugin does a better job picking related posts than Jekyll’s built-in approach, though I have no idea why. Jekyll usually ended up with nothing related, and just defaulted back to the most recent posts. This works better for me.

For the moment I prefer a comma-delimited dump of posts. Later I may play with some list styling. However, I did have the problem of post titles being broken up by line breaks. A little white-space: nowrap in the right spot fixes that.

a.post-link {
  white-space: nowrap;
}

Now the text of each post link stays together.

Just wanted to share all this. Have fun!

Indieweb Social

Did you mention this somewhere? I'd love it if you sent me the link!

disclaimer about timing

Mentions are sent to webmention.io. I fetch the latest mentions when building the site, so I may not see your feedback right away. Especially if my site's broken, which is often the case.

Public replies and mentions might be shared on the site, but I try to do a little quality check first.

Site Links