mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-30 03:03:09 +00:00
theme: open external links in separate tab feature #419
This commit is contained in:
parent
95e07665a7
commit
39d685f566
3 changed files with 18 additions and 5 deletions
|
@ -16,6 +16,8 @@ This document shows you what's new in the latest release. For a detailed list of
|
||||||
|
|
||||||
## 5.9.0 (not yet released)
|
## 5.9.0 (not yet released)
|
||||||
|
|
||||||
|
- {{% badge style="note" title=" " %}}Change{{% /badge %}} Absolute links prefixed with `http://` or `https://` are now opened in a separate browser tab.
|
||||||
|
|
||||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme now supports [Hugo's module system](https://gohugo.io/hugo-modules/).
|
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme now supports [Hugo's module system](https://gohugo.io/hugo-modules/).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<!-- This code opens an external link in a new tab. -->
|
{{- partial "shortcodes/link.html" (dict
|
||||||
|
"context" .Page
|
||||||
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>
|
"url" .Destination
|
||||||
{{ .Text | safeHTML }}
|
"title" .Title
|
||||||
</a>
|
"content" .Text
|
||||||
|
) }}
|
10
layouts/partials/shortcodes/link.html
Normal file
10
layouts/partials/shortcodes/link.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{{- $context := .context }}
|
||||||
|
{{- $url := .url }}
|
||||||
|
{{- $title := .title | default "" }}
|
||||||
|
{{- $title = trim $title " " }}
|
||||||
|
{{- $content := .content }}
|
||||||
|
{{- $target := .target | default "" }}
|
||||||
|
{{- if and (eq (len $target) 0) (or (strings.HasPrefix $url "http://") (strings.HasPrefix $url "https://") ) }}
|
||||||
|
{{- $target = "_blank" }}
|
||||||
|
{{- end -}}
|
||||||
|
<a href="{{ $url | safeURL }}"{{ if $title }} title="{{ $title }}"{{ end }}{{ if gt (len $target) 0 }} target="{{ $target }}" rel="noopener"{{ end }}>{{ $content | safeHTML }}</a>
|
Loading…
Reference in a new issue