Jekyll Meta Includes

 The Problem

In Jekyll, I have a lot of code that will include a <meta> tag if a certian property is set.

The code for this looks terrible, and is terribly repetative.

{% if site.title %}
    <meta property="og:site_name" content="{{ site.title }}" />
{% endif %}

{% if page.url %}
    <meta property="og:url" content="{{ page.url }}" />
{% endif %}

{% if page.thumbnail %}
    <meta property="og:image" content="{{ page.thumbnail }}" />
{% endif %}

{% if page.date %}
    <meta property="article:published_time" content="{{ page.date }}" />
{% endif %}

Yuck!

 The Solution

I have come up with a solution!

Using Jekyll’s (new?) Include paramaters, I can create one file that checks
to see if a certian variable exists and – if so – will include the proper <meta> tag.

This file looks like this.

{% if include.content %}
<meta property="{{ include.property }}" content="{{ include.content }}" />
{% endif %}

Now, the code to include a list of meta tags looks much more readable.

{% include meta.html property="og:site_name" content=site.title %}
{% include meta.html property="og:url" content=page.url %}
{% include meta.html property="og:image" content=page.thumbnail %}
{% include meta.html property="article:published_time" content=page.date %}
 
13
Kudos
 
13
Kudos

Now read this

WebVTT Observations

Update The WebVTT Draft Spec has been updated to allow metadata headers. This corrects all the issues outlined in this post. :) According to the WebVTT Draft Spec, a WebVTT file must start with the string “WEBVTT” followed by some text... Continue →