{{/* Get name of primary author. */}}

{{ $page := . }}

{{/* Get publisher as fall back. */}}
{{ $publisher := site.Params.org_name | default site.Title }}

{{ $author := "" }}
{{ $author_username := "" }}

{{ if and (not $page.Params.authors) ($page.Scratch.Get "superuser_username") }}
  {{ $author_username = $page.Scratch.Get "superuser_username" }}
{{ else if $page.Params.authors }}
  {{ $author = index $page.Params.authors 0 }}
  {{ $author_username = urlize $author }}
{{ end }}

{{ $taxonomy := "authors" }}
{{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_username) }}
{{ with $profile_page }}
  {{ $author = .Title }}
{{ else }}
  {{ $author = $author | default $publisher }}
{{ end }}

{{ return $author }}
