Skip to content

Commit 7a3a04e

Browse files
rohitbharmalcursoragent
andcommitted
Open external links in new tab (fixes #4314)
- Add Hugo link render hook so markdown external links get target=_blank and rel=noopener noreferrer - Add rel=noopener noreferrer to navbar and feedback partials for external links Signed-off-by: rohitbharmal <rbharmal@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7264005 commit 7a3a04e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- $dest := .Destination -}}
2+
{{- $isExternal := or (strings.HasPrefix $dest "http://") (strings.HasPrefix $dest "https://") (strings.HasPrefix $dest "//") -}}
3+
<a href="{{ $dest | safeURL }}"
4+
{{- with .Title }} title="{{ . }}"{{ end -}}
5+
{{- if $isExternal }} target="_blank" rel="noopener noreferrer"{{ end -}}>
6+
{{- .Text | safeHTML -}}
7+
</a>

layouts/partials/feedback.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h3 class="card-title">Feedback</h3>
1212
{{- if .File }}
1313
{{- $gh_repo := ($.Param "github_repo") }}
1414
{{- $issuesURL := printf "%s/issues/new?title=[Feedback]+%s" $gh_repo (safeURL .File.Path) }}
15-
If you have a moment, please <a href="{{ $issuesURL }}" target="_blank">share your feedback</a> so we can improve.
15+
If you have a moment, please <a href="{{ $issuesURL }}" target="_blank" rel="noopener noreferrer">share your feedback</a> so we can improve.
1616
{{- end }}
1717
</p>
1818
</div>

layouts/partials/navbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<a {{/**/ -}}
5050
class="nav-link {{- if $active }} active {{- end }}" {{/**/ -}}
5151
href="{{ with $e.Page }}{{ $e.RelPermalink }}{{ else }}{{ $e.URL | relLangURL }}{{ end }}"
52-
{{- if ne $url.Host $baseurl.Host }} target="_blank" {{- end -}}
52+
{{- if ne $url.Host $baseurl.Host }} target="_blank" rel="noopener noreferrer"{{ end -}}
5353
>
5454
{{- with $e.Pre }}{{ $pre }}{{ end -}}
5555
<span {{- if $active }} class="active" {{- end }}>

0 commit comments

Comments
 (0)