Author information in jekyll blog

Neeraj Singh

By Neeraj Singh

on January 9, 2015

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.

2  name: Vipul
3  avatar:
4  github: vipulnsward
5  twitter: vipulnsward
7  name: Neeraj Singh
8  avatar:
9  github: neerajdotname
10  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.

2layout: post
3title: How to deploy jekyll site to heroku
4categories: [Ruby]
5author_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.

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

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

1{% raw %}
2<a href="{{[page.author_github].twitter}}">
3  <i class="ico-twitter"></i>
5<a href="{{[page.author_github].github}}">
6  <i class="ico-github"></i>
8{% endraw %}

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

Stay up to date with our blogs. Sign up for our newsletter.

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