Author page is displayed twice

This is what chatgpt told me try it out
Your code is currently looping through each page in the paginator and then, for each page, looping through the list of authors. This is causing the duplicate author entries for pages that share the same author.

To fix this, you should first gather a unique list of authors and then loop through that list. Here’s a solution to avoid duplicate authors:

  1. First, create a set of unique authors.
  2. Next, loop through the unique set to display author details.

Here’s how you can do it:

<div class="content-box">
{{ $uniqueAuthors := slice }}
{{ range .Paginator.Pages }}
  {{ range .Param "authors" }}
    {{ $name := . }}
    {{ if not (in $uniqueAuthors $name) }}
      {{ $uniqueAuthors = $uniqueAuthors | append $name }}
    {{ end }}
  {{ end }}
{{ end }}

{{ range $uniqueAuthors }}
  {{ $name := . }}
  {{ $path := printf "/%s/%s" "authors" ($name | urlize) }}
  {{ with $.Site.GetPage $path }}
    <div class="list-content" style="background:none !important;">
      <h2>{{ .Params.name }}</h2>
      <div class="ImgAut">
        <img src="/images{{ $path }}.png">
      </div>
      <p>{{ .Params.bio }}</p>
    </div>
  {{ end }}
{{ end }}
</div>

Here’s the breakdown of the changes:

  1. Initialize an empty slice $uniqueAuthors to store unique author names.
  2. Loop through all the pages and their authors, and only append the author to the $uniqueAuthors slice if they haven’t been added already.
  3. Once you have the unique authors, loop through them to display their details.

This approach ensures that each author is displayed only once, regardless of how many times they appear in the list of authors across different pages.

1 Like