BigBinary Blog

We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.

Author information in jekyll blog

BigBinary's blog is powered by jekyll. In every blog we display author's name, author's twitter handle, author's github id and author's avatar. In this blog I'm going to discuss how we collect all that information in a simple manner.

We create a directory called _data in the root folder. This directory has a single file called authors.yml which in our case looks like this.

  name: Vipul
  github: vipulnsward
  twitter: vipulnsward
  name: Neeraj Singh
  github: neerajdotname
  twitter: neerajdotname

We do not need to do anything to load authors.yml . It is automatically loaded by jekyll.

When we create a blog then the top of the blog looks like this.

layout: post
title: How to deploy jekyll site to heroku
categories: [Ruby]
author_github: neerajdotname

Notice the last line where we have put in the author's github id. That's the identifier we use to pull in author's information.

In order to display author's name we have following code in the layout.

{% raw %}
<span class="author-name">
  {{[page.author_github].name }}
{% endraw %}

Similarly to display author's twitter handle and github id we have following code.

{% raw %}
<a href="{{[page.author_github].twitter}}">
  <i class="ico-twitter"></i>
<a href="{{[page.author_github].github}}">
  <i class="ico-github"></i>
{% endraw %}

Now the blog will display the author information and all this information is nicely centralized in one single file.

Neeraj Singh in Ruby
09, 2015

You might also like

Ruby 3 is released - The list of Ruby 3 features

Ruby 3 supports transforming hash keys using a hash argument

Ruby 3 adds new method Hash#except

Ruby 3 adds Symbol#name

Ruby 3 adds endless method definition

Subscribe to our newsletter