{{- $class := "" -}}
{{- $icon := "" -}}
{{- $absoluteDest := absLangURL .Destination -}}
{{- $siteRootUrl := absLangURL "" -}}
{{- $isExternal := not (hasPrefix $absoluteDest $siteRootUrl) -}}
{{- $isSamePage := hasPrefix .Destination "#" -}}

{{- if $isSamePage -}}
  {{- $class = "same-page-link" -}}
  {{- if index (.Page.Store.Get "definedSections") .Destination -}}
    {{- $icon = "arrow-up" -}}
  {{- else -}}
    {{- /* Do not render "down" links because don't know how to distinguish unseen titles from paragraph links. */ -}}
    {{- /* $icon = "arrow-down" */ -}}
  {{- end -}}
{{- else if $isExternal -}}
  {{- $class = "external-link" -}}
  {{- $icon = "external-link" -}}
{{- end -}}
<a href="{{ .Destination | safeURL }}"
  {{- with .Title }} title="{{ . }}"{{ end -}}
  {{- with $class -}}
    class="{{ . }}"
  {{- end -}}
  {{- if (and site.Params.externalLinksInNewTab $isExternal) -}}
    target="_blank" rel="noopener noreferrer"
  {{- end -}}
>
  {{- with .Text | safeHTML }}{{ . }}{{ end -}}
  {{- with $icon -}}{{- partial "icon.html" . -}}{{- end -}}
</a>
{{- /* chomp trailing newline */ -}}
