Skip to content

Instantly share code, notes, and snippets.

@neerajsingh0101
Created January 11, 2015 03:29
Show Gist options
  • Save neerajsingh0101/119a609805b928038c81 to your computer and use it in GitHub Desktop.
Save neerajsingh0101/119a609805b928038c81 to your computer and use it in GitHub Desktop.
---
layout: post
title: Author information in jekyll blog
published: true
categories: [ruby]
description: Author information in jekyll blog
author_github: neerajdotname
---
BigBinary's [blog](http://blog.bigbinary.com)
is powered by [jekyll](http://jekyllrb.com).
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.
```
vipulnsward:
name: Vipul
avatar: http://bigbinary.com/assets/team/vipul.jpg
github: vipulnsward
twitter: vipulnsward
neerajdotname:
name: Neeraj Singh
avatar: http://bigbinary.com/assets/team/neeraj.jpg
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">
{{ site.data.authors.[page.author_github].name }}
</span>
{% endraw %}
```
Similary to display author's twitter handle
and
github id
we have following code.
```
{% raw %}
<a href="www.twitter.com/{{site.data.authors.[page.author_github].twitter}}">
<i class="ico-twitter"></i>
</a>
<a href="www.github.com/{{site.data.authors.[page.author_github].github}}">
<i class="ico-github"></i>
</a>
{% endraw %}
```
Now the blog will display the author information
and
all this information
is nicely centralized
in one single file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment