{{- $Scratch := newScratch }}
{{- $site := .site }}

{{- $affiliations := .affiliations }}
{{- range .authors }}
  {{- $author := . }}
  {{- $affils := "" }}
  {{- with $affiliations }}
    {{- if isset . $author }}
      {{- $affil := index . $author }}
      {{- if eq (isset $affil "homepage") true }}
        {{- $affils = printf "%s [🌐](%s)" $affils (index $affil "homepage") }}
      {{- end }}
      {{- if eq (isset $affil "email") true }}
        {{- with (index $affil "email") }}
        {{- $affils = printf "%s <a class=\"obfuscated\" data=\"%s\">📧</a>" $affils
            (. | jsonify | base64Encode) }}
        {{- end }}
      {{- end }}
    {{- end }}
  {{- end }}

  {{- $author := printf "[%s](%s%s)%s"
    (index (index $site.Site.Data.authors .) "name")
    ("/authors/" | relLangURL)
    (. | urlize)
    $affils
  }}
  {{- $Scratch.Add "authors" (slice $author) }}

{{- end }}

{{- delimit ($Scratch.Get "authors")  ", " | replaceRE "(, )([^,]+$)" " and $2" | safeHTML
    | .site.RenderString | safeHTML }}
