1
votes

I'm back to work on a jekyll project. When I first started working on this project, I asked on this page how to pull an author's name in a jekyll post, and was advised to use this code:

   {{ site.data.authors[page.author].name }}

...which worked fine. Now my goal is to have an authors page on which to display author info. I have a authors.yml file (in the _data file) with items structured as follows :

john_doe:    
name: John Doe    
email: [email protected]

I have used the Jekyll guidelines and my code goes like this in the authors.md page :

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

I know the first part of the code is functional because I have a bullet point showing for each author i.e list item. However the list items return empty without the author's name (eventually I would like to pull more info from the yml, but since I can't get through this first step...)

I tried switching to this structure, with no success:

   - name : john_doe 
   - email: [email protected]

Second issue: I also have set links to extra pages using a navigation.yml file with links sorted like so:

- title: A propos
  url: /about/
  excerpt: ""

These urls worked fine locally but no such luck after I pushed it on the repo...

If anyone has any ideas... I'm stuck! My repo: https://github.com/piapandelakis/piapandelakis.github.io

1

1 Answers

2
votes

Create a data file _data/authors.yml with the following content:

john_doe:    
  name: John Doe    
  email: [email protected]
rms:
  name: Richard Stallman
  email: [email protected]

This structure has the benefit that you can in addition to being able to loop over all the authors, you can access any of them individually whenever you need to.

In a post with the author rms you can display its info:

---
author: rms
---

{% assign author = site.data.authors[page.author] %}
<div> Author: {{ author.name }}
</div>

To show a list of all authors:

{% for author in site.data.authors %}
{{author[1].name}} <br>
{% endfor %}