vanilla-hugo/layouts/_default/_markup/render-link.html

31 lines
1.0 KiB
HTML
Raw Normal View History

{{- $scratch := newScratch -}}
{{- $absoluteDest := absLangURL .Destination -}}
{{- $siteRootUrl := absLangURL "" -}}
{{- $isExternal := not (hasPrefix $absoluteDest $siteRootUrl) -}}
{{- $isSamePage := hasPrefix .Destination "#" -}}
{{- if $isSamePage -}}
{{- $scratch.Set "class" "same-page-link" -}}
{{- if index (.Page.Scratch.Get "definedSections") .Destination -}}
{{- $scratch.Set "icon" "arrow-up" -}}
{{- else -}}
{{- $scratch.Set "icon" "arrow-down" -}}
{{- end -}}
{{- else if $isExternal -}}
{{- $scratch.Set "class" "external-link" -}}
{{- $scratch.Set "icon" "external-link" -}}
{{- end -}}
<a href="{{ .Destination | safeURL }}"
{{- with .Title }} title="{{ . }}"{{ end -}}
{{- with $scratch.Get "class" -}}
class="{{ . }}"
{{- end -}}
{{- if $isExternal -}}
target="_blank" rel="noopener noreferrer"
{{- end -}}
>
{{- with .Text | safeHTML }}{{ . }}{{ end -}}
{{- with $scratch.Get "icon" -}}{{- partial "icon.html" . -}}{{- end -}}
</a>
{{- /* chomp trailing newline */ -}}