3
votes

So I have a file, authors.yml, inside my Jekyll _data folder. It's set up like this:

short_name:
  name: First Lastname
  email: [email protected]
  twitter: twitterID
  image: image.jpg
  bio: 'Bio goes here.'

I'd like to make a listing page of each author in this file. This is what i have tried:

<ul>
{% for author in site.data.authors %}
  <li>{{ author.name }}</li>
{% endfor %}
</ul>

What this returns is a number of empty list tags that matches the number of authors in the file.

I'm wondering if there's any way to display the data contained in each author without resorting to the following in the YAML file (as it breaks other code on the site):

-author: short_name
  name: First Lastname
  email: [email protected]
  twitter: twitterID
  image: image.jpg
  bio: 'Bio goes here.'

Is this possible?

Alternatively, the code that is broken when I add the 'author' key is the following.

In a template:

{% assign author = site.data.authors[post.author] %}

And in a plugin:

 entry_name = site.data['authors'][entry.author]
3

3 Answers

1
votes

I'm not sure if this is what you're after but I've been trying to solve a similar problem.

{% for member in site.data.authors %}
    {% if member.short_name == post.author %}
        {% assign author = member %}
    {% endif %}
{% endfor %}

For this to work, I needed to include a short_name item in my data. See below:

- author: short_name
  name: First Lastname
  short_name: first_lastname
  email: [email protected]
  twitter: twitterID
  image: image.jpg
  bio: 'Bio goes here.'

Now we can use {{ author.name }} etc in the template.

1
votes

I've actually written a blog post on this subject. In the _data file, you just need to create a new entry for each set of author attributes you want to display.

So, if you change the authors.yml file to look like this:

- name: John Doe
  email: [email protected]
  twitter: @johndoe

- name: Mary Doe
  email: [email protected]
  twitter: @notjohndoe

Then you can just reference the attribute you are looking for on the author object:

{% for author in site.data.authors %
  {% author.name %}
  {% author.email %}
  ... etc ...
{% endfor %}

Hope that helps.

0
votes

I had this same question. Here is the best solution.

This is an excerpt from my layout file:

---
layout: sidebar-container
author: paul
includeHeader: blog-image.html
---

{% assign author = site.data.people.[page.author] %}


<article class="container">
    <header>
        <h1 class="title">{{ page.title }}</h1>
        {% if page.subtitle %}<h2 class="subtitle">{{ page.subtitle }}</h2>{% endif %}
        <div class="meta">
            By <address><a rel="author" href="{{ author.link }}" title="{{ author.name }}" target="_blank">{{ author.name }}</a></address> &mdash;
            <time pubdate datetime="{{ page.date | date: "%Y-%d-%B" }}" title="{{ page.date | date: "%B %d, %Y" }}">{{ page.date | date: "%B %d, %Y" }}</time>
        </div>
    </header>

Here is my data file named 'people.yml'

dave:
    id: dave
    name: David Smiths
    link: /bitcoin-expert/
    twitter: DavidSilvaSmith
    image: http://www.gravatar.com/avatar/7bbd083ea04a3c791e878da24c08b987.png
    bio: David is the CEO of bitcoin bulls.

paul:
    id: paul
    name: Paul
    link: http://www.paulsmith.com
    twitter: PaulSmith
    image: http://www.cs.mcgill.ca/~kry/kry-acm1.png
    bio: Paul Smith rocks