mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
Merge pull request #2717 from pwhittlesea/optional-new-tab-on-external-links
✨ Feat: Add option for external link in new tab
This commit is contained in:
@@ -22,9 +22,17 @@
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Open external links in a new tab if
|
||||
configured to do so by the page param externalLinkForceNewTab
|
||||
or site param article.externalLinkForceNewTab
|
||||
and the link starts with http: or https:
|
||||
*/}}
|
||||
{{- $forceNewTab := .Page.Params.externalLinkForceNewTab | default (.Page.Site.Params.article.externalLinkForceNewTab | default true) -}}
|
||||
{{- $isExternal := or (strings.HasPrefix .Destination "http:") (strings.HasPrefix .Destination "https:") -}}
|
||||
{{- $newTab := and $forceNewTab $isExternal -}}
|
||||
|
||||
<a href="{{ $href }}" {{ with .Title }}title="{{ . }}"{{ end }}
|
||||
{{- if or (strings.HasPrefix .Destination "http:") (strings.HasPrefix .Destination "https:") }} target="_blank"{{ end }}>
|
||||
{{- if $newTab }} target="_blank" rel="noreferrer"{{ end }}>
|
||||
{{- .Text | safeHTML -}}
|
||||
</a>
|
||||
{{- /* Trim EOF */ -}}
|
||||
|
||||
Reference in New Issue
Block a user