Create an author index where duplicate values are nested

#1

I’m trying to build an alphabetized index for all the authors listed on my site. Currently, authors whose first names have the same letter are getting duplicate entries:

{% assign people = site.data.book-data | sort: 'author' %}
<ul class="people-index-entries">
  {% for p in people %}
  <li class="index-entry">
    <h2 id="{{ p.author | slice: 0 }}" class="index-heading">{{ p.author | slice: 0 }}</h2>
    <a href="{{ site.baseurl }}/reviews/{{ p.name}}">{{ p.author }} – {{ p.title }}</a>
  </li>
  {% endfor %}
</ul>

I’m trying to find a way to get authors listed under a single letter. I was wondering if this might be possible with a where filter – something along the lines of:

{% assign A = site.data.book-data | where: "author", "" %}

Is it possible to have a filter inside a filter? That is, could I do something like:

{% assign A = site.data.book-data | where: "author", "{{ entry.author | slice: 0 == A }}" %}

Not sure if I’m on the right track here, so any suggestions welcome. Here is an example of an entry in my data file:

- name: cusk-outline
  title: Outline
  author: Rachel Cusk
  thumbnail: cusk-outline.jpg
  publisher: Faber & Faber
  pub-date: 3rd May, 2018
  extents: 256pp.
#2

did you get it to work? your link looks like it is correct but there isn’t very many people so it may not be showing the problem.

Sounds like you would need an outer loop to do the letter, and then an inner loop inside that to do the people. That said I am not quite sure what the outer loop would look like.

#3

sorry, i was meant to update the post. basically, i cheated by adding an index: [letter] key/value pair to each entry in the data set, then using a group_by filter to nest each entry with the same index value under the letter headings. sorry if that doesn’t make a whole lot of sense, but you can see the commit here.