Skip to main content
This article is a little old. The information herein might not be too accurate.

Adding authors to your Jekyll site

Keen readers of our blog may have noticed we now credit our posts to their author. This is how we do it.

Define your authors

First you need somewhere to store the authors details. While we could put this in our _config.yml, ideally we’d like to keep this in it’s own configuration file. Create a file in _data/authors.yml containing your authors information.

# Author details.
robert_rawlins:
    name: Robert Rawlins
    email: robert@sorryapp.com
    web: http://twitter.com/sirrawlins
robin_geall:
    name: Robin Geall
    email: robin@sorryapp.com
    web: http://twitter.com/robingeall

Attribute a post to an author

To reference an author we add their key (which we defined in the _data/authors.yml) to the individual posts front-matter, we’ll use this later to pull the full details of the author for display.

---
# Layout.
layout: post

# Author.
author: robert_rawlins
---

Display the author's details on the post

Now we have a reference to our authors key in the posts front-matter, we need to get ourselves the full author details and assign it to a variable.

Once we have this we can output the details of the author as we see fit. I keep this code in the top of my _layouts/post.html

<!-- Look the author details up from the site config. -->
{% assign author = site.data.authors[page.author] %}

<!-- Output author details if some exist. -->
{% if author %}
    <span>
        <!-- Personal Info. -->
        Written by <a href="{{ author.web }}" target="_blank">{{ author.name }}</a>
    </span>
{% endif %}

You’ll note I wrapped the output in an if statement, just to ensure that the author is found and assigned.

Rebuild and admire

Once your site has been rebuilt you should have the author attributed at the top of your post.

I’ll soon show how we added the Gravatar photo’s, and how we get those photo’s pulled through next to our Google search results.