This is the first “finished” bit of code in this project. It’s a snippet you can use to put a list of birds at the bottom of posts on your Jekyll blog.

Copy the code into a post (or more likely, your posts template in _layouts/post.html) and it will read a list of birds from your YAML front matter and put them into your post, sorted alphabetically.

The code is available in its most up to date form in this Gist, but at the time of writing it looks like this:

<div class="birdlist">
  {% if page.birds %}
  <hr>
  <h3>Birds in this entry:</h3>
    <div class="birdstring">
    {% assign birdies = page.birds | sort %}
    {% for birdy in birdies %}
      {% unless birdy == birdies.last %}
      {{ birdy }}, 
      {% endunless %} 
    {% endfor %}
    {% if birdies.size > 1 %}
    and 
    {% endif %} 
    {{ birdies.last }}.
    </div>
  {% endif %}
</div>

Your YAML list can be in a number of formats. I do it like this:

---
date: 2015-01-28
title: "First public release"
birds:
  - penguin
  - ostrich
  - pterodactyl
  - Gwaihir the Windlord
---

but this is equally valid:

---
date: 2015-01-28
title: "First public release"
birds: [Wren, Blackbird, Blue Tit, Dunnock, Robin]
---

Below is a demo of the output derived from this code:


Birds in this entry:

Gwaihir the Windlord, ostrich, penguin, and pterodactyl.