Last active
January 3, 2020 14:27
-
-
Save inwardmovement/734cd02cd4b17172e07a0c8456c4151d to your computer and use it in GitHub Desktop.
Open external links in new tabs with Hugo (using render hooks)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="{{ .Destination | safeURL }}" {{ if ne true (hasPrefix .Destination .Site.BaseURL) }} rel="external nofollow"{{ end }}>{{ .Text }}{{ if ne true (hasPrefix .Destination .Site.BaseURL) }} {{ (resources.Get "icons/box-arrow-up-right.svg").Content | safeHTML }}{{ end }}</a> | |
or | |
(strings.HasPrefix .Destination .Site.BaseURL) | |
or | |
(in (urls.Parse .Destination).Host (urls.Parse .Site.BaseURL).Host) | |
--- | |
Check if starts with "http"? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment