1

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: john@website.com

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: john@email.com

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

PiaP
  • 15
  • 2

1 Answers1

2

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

john_doe:    
  name: John Doe    
  email: john@website.com
rms:
  name: Richard Stallman
  email: rms@gnu.org

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 %}
marcanuy
  • 23,118
  • 9
  • 64
  • 113
  • It works perfectly! I was stuck between the two syntax options(dash or no dash in the author YML...it never worked on both pages simultaneously). This did the trick, thank you so much for taking the time to help me ! :) – PiaP Aug 06 '17 at 21:38
  • There still is the URL issue... should I open a new thread for that? – PiaP Aug 07 '17 at 09:19
  • Note, if the WordPress importer was used the correct assignment is: `{% assign author = site.data.authors[page.author.login] %}` – K. Frank Sep 01 '21 at 01:42