In my previous posts, I have shown ways to add a lot of metadata to a Jekyll blog’s posts. However, the use of the metadata shouldn’t be left just for the search engines and social network sites. You too can benefit from the added metadata many sites expose these days.

The Discourse project shows a “onebox” when a user posts a link in a discussion thread. This functionality is available as its own gem and because it’s in Ruby, it’s easy to integrate with a Jekyll blog as well.

The one assumption onebox makes that doesn’t really fit a blog is that it uses a whitelist. Below, the Liquid filter adds my own blog to the whitelist but for more general use I should override the whole whitelisting.

# onebox_filter.rb
require "onebox"

Onebox::Engine::WhitelistedGenericOnebox.whitelist << "kalifi.org"

module Jekyll
  module OneboxFilter
    def preview(url)
      Onebox.preview(url).to_s
    end
  end
end

Liquid::Template.register_filter(Jekyll::OneboxFilter)

The example usage for the filter is that you can write in your article

{{ "http://kalifi.org/2015/08/using-discourse-onebox-with-jekyll.html" || preview }}

to get this

Pretty neat. The downside in using a Liquid filter is that you’re mixing Markdown with Liquid markup which is not really optimal. A better solution would be to yet again extend Kramdown (or whichever converter you use) to support custom markup.

However, as you can see I have no event finished matching onebox’s built-in CSS with my site…