I have an author system implemented where the frontmatter of pages includes things like this:
---
authors:
- bruno-amaral
- pedro-rodrigues
---
My problem is that not every page has an author, and some include only one author. The first one is always the main to display in the frontend.
I was trying to use {{ with (index .Params.authors 0) }}
but I still get an error executing "shortcodes/blog-6.html" at <index .Params.authors 0>: error calling index: index of untyped nil
{{ $ref := (.Get "ref") }}
{{ $page := "" }}
{{ range .Page.Sites }}
{{ if eq (print (.GetPage $ref).File) $ref }}
{{ $page = (.GetPage $ref) }}
{{ end }}
{{ end }}
{{ with $page }}
{{ $author := "" }}
{{ $avatarimage := ""}}
{{ with (index .Params.authors 0) }}
{{ $author = $.Site.GetPage (printf "authors/%s/" (index .Params.authors 0) )}}
{{ else }}
default author:
{{ $author = $.Site.GetPage "authors/bruno-amaral/" }}
{{ end }}
{{end }}