Render-link hook: support a no-icon class (#857)

This commit is contained in:
Patrice Chalin 2021-09-17 16:56:49 -04:00 committed by GitHub
parent 551ddf1411
commit 9983507f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -1,11 +1,14 @@
{{ $isRedirected := findRE "^(|../|/docs/(languages|platforms)/.+?/)(api|daily-builds)(/.*)?(\\?.*)?$" .Destination -}}
{{ $isExternal := or (hasPrefix .Destination "http") $isRedirected -}}
{{/* Until Hugo supports hook params (https://github.com/gohugoio/hugo/issues/6670), we'll inspect .Text. */ -}}
{{ $noExternalIcon := in .Text "hk-no-external-icon" -}}
<a href="{{ .Destination | safeURL }}"
{{- with .Title }} title="{{ . }}"{{ end -}}
{{- if $isExternal }} target="_blank" rel="noopener"{{ end -}}
>
{{- .Text | safeHTML -}}
{{ if $isExternal -}}
{{ if and $isExternal (not $noExternalIcon) -}}
<i class="fas fa-external-link-alt"></i>
{{- end -}}
</a>
</a>
{{- /* This directive ensures that all trailing whitespace is trimmed. */ -}}