Help with author pages

I haven’t had time to look at this further, and probably won’t have chance for a while. I have to prioritize other work at the moment.

Okay, thanks Jonathan. Single author works as of now, which does the trick. Multi-author support would be amazing down the road, if only to cover this use-case. If you do get around to it, please let me know. Again, amazing support and very much appreciated!

This is a crazy long thread, so I’m a bit lost, but am I missing something w/r/t the idea of “multiple authors?” Why not a simple authors taxonomy?

This thread was more of a learning exercise for me ( a newbie), helping out someone else. Hence the long thread, as I started off not really knowing how to implement it.

The implementation was using authors taxonomy, but the difficulty related to displaying things like bio \ photo etc on post article page.

Displaying all that info on the taxonomy page is not really an issue, as that is fairly simple.

We managed to retrieve the information from the taxonomy _index.md file for single authors to display on the post article page, but unfortunately it was like 3 am in the morning when I was looking at this, and haven’t had time to look into it working with multiple authors.

@rdwatters That is what we went with, but the code that grabs and compares the frontmatter in each individual _index.md (pertaining to a single author) currently does not work when using multiple authors in a post’s frontmatter.

To summarize, in multiple _index.md, for each author, I have frontmatter like this:

name: Joe
bio: this is a bio
photo: /path/to/img/

Then when creating a post, there is an authors taxonomy in the front matter, which lets us specify N number of authors. However, the code to match Joe and also extract the bio and photo from his _index.md for use across list and single pages currently only loops through a single author properly.

so this works:

authors: Joe

but this does not:

authors: [ "alan", "joe"]

and the code that Jonathan wrote that needs to support multiple authors is this -

{{ $postauthor := .Params.authors }}
{{ range where (where .Site.Pages "Type" "authors") ".Params.name" "=" $postauthor }}
{{ .Params.testparams }}
{{ end }}

Any help is much appreciated.

Gotcha. Thanks for the update. Frankly, it was my bad for being lazy and not reading the preceding comments :smile:

So here is what I would recommend:

  1. I assume you have author = "authors" in your config.toml under [taxonomies].
  2. I assume, for example, that if you have an author named Ryan Watters, you have a content file for said author at content/authors/ryan-watters/_index.md.
  3. I assume that when you add an author to a content file, you do so using authors = ["Ryan Watters", "John Doe"], etc…

So here is what you need for something like layouts/_default/single.html:

<!--Somewhere in layouts/_default/single.html-->
{{ with .Params.authors }}
      {{ range $ind,$val := . }}
           {{$author := $val | urlize }}
           {{- with $.Site.GetPage "taxonomyTerm" "authors" $author}}
           <p>Name = {{ .Params.name }} </p>
           <p>Bio = {{ .Params.bio }}</p>
           <p>Photo = {{.Params.photo}}</p>
           <p>Here is the content from this author's _index.md file:</p>
          {{.Content}}
      {{ end -}}
  {{ end }}
{{ end }}

Obviously you can use whatever elements you want…

2 Likes

Thanks @rdwatters! Your assumptions are all correct. I tried your code and it errored out when I had some content pages with authors: alan (as that was what worked before with Jonathan’s code).

I switched to the multi-format you listed above and there are no Hugo errors. However, I am not seeing your code displayed on the page. I added text around it to make sure it wasn’t weird caching, and nothing in your code renders. Is there any way to console.log hugo steps to the CLI? Or how would I go about debugging this, if your code is working on your end?

The best way is to put your source in a place where you can share it and then I can test it locally.

As for authors: alan, yes, you should be treating all your taxonomies in front matter like an array, regardless of how many values you add to each content file…

What page isn’t rendering? I need more context.

What hugo version are you running?

Sorry for the delayed response. The pages render fine @rdwatters but your code renders nothing (like I don’t have any markup). My hugo version is 0.21

Attaching screenshots - Maybe you can see something I am not seeing @rdwatters

This is the frontmatter in a post (I just have one post to rule out issues)

here is my config.toml

here is my _index.md inside /authors/

Here is my single.html

And this is what renders (notice how HELLO WORLD is displayed with nothing in the middle)

@Alan_Roy Can you please put this source somewhere so that I can run it locally? This thread has 44 posts, screenshots, etc, and source could really help consolidate our efforts. Thanks!

Sure @rdwatters , but I have to separate it out from the main project and I may not have time this weekend. I’ll post when I do. Alternatively, if you have a working dummy version up somewhere, I could compare it as well. Much appreciated!

Where can I read this Chemex post? I could certainly use some help with my blooms. :yum:

@Jonathan_Griffin @rdwatters Sorry for bringing this back up. I have been successfully using Jonathan’s single author implementation. I was wondering if there was any development on your ends for multi-author support in the time since we last spoke. I will try to post a repo if needed as well.

Hey Alan, I wrote an extensive tutorial on how to use taxonomies. You can check it out here: Handling taxonomies like a boss - update

Check it out. You can use multiple multiple authors with this approach.

If you still feel confused, I’ll be happy to help you. It will help me to get better with taxonomies. Just point me to your repo.

1 Like

@guayom thank you! I’m so close. Using the code in here (https://github.com/guayom/hugo-taxonomies/blob/master/layouts/partials/brand-list.html), I have been able to list multiple authors per page. However, I have additional frontmatter in each author’s page that I would like to surface on the single and summary layouts, so how would I edit the snippet I linked above to access the field of photoThumb: "/img/team-photos/joe@2x-sm@2x.jpg" inside of joe/_index.md ?

My main objective is to show a photo thumbnail next to the name. My markup (which worked in the single author approach looked like this)

 {{ $postauthor := .Params.authors }}
{{ range where (where .Site.Pages "Type" "authors") ".Params.name" "=" $postauthor }}
<a href="/authors/{{ .Params.name | urlize}}">

<img class="img-circle img-thumb" src="{{ .Params.photoThumb }}">
{{ .Params.firstName }} {{ .Params.lastName }} <!-- {{ .Params.jobtitle }} --></a>
{{ end }}

@guayom to put it in the context of your example repo, it would be the equivalent of surfacing the Adidas Logo inside a single product page, next to the brand name.

Could this be what you’re looking for?

<ul>
  {{ range ($.Site.GetPage "taxonomyTerm" "authors").Pages }}
   <li>
       <a href="{{ .Permalink }}">
         <img class="img-circle img-thumb" src="{{ .Params.photoThumb }}">
         {{ .Params.firstName }} {{ .Params.lastName }} <!-- {{ .Params.jobtitle }} -->
       </a>
   </li>
  {{ end }}
</ul>

@guayom it’s close, but it seems to be posting every author instead of the author that is specified in the post’s frontmatter. I took your code and replaced it with just the first name.