Skip to content

Commit ace996b

Browse files
committed
theme: make external link target configurable matcornic#426
1 parent 94e91d5 commit ace996b

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

exampleSite/content/basics/configuration/_index.en.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Note that some of these parameters are explained in details in other sections of
8686
# If set to true, no index.html will be appended to prettyURLs; this will cause pages not
8787
# to be servable from the file system
8888
disableExplicitIndexURLs = false
89+
# For external links you can define how they are opened in your browser; this setting will only be applied to the content area but not the shortcut menu
90+
externalLinkTarget = "_blank"
8991
```
9092

9193
## Serving your page from a subfolder

exampleSite/content/basics/migration/_index.en.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This document shows you what's new in the latest release. For a detailed list of
2222

2323
This added unnessessary complexity. So attachments for leaf bundles in non-multilang setups can now also reside in a `index.files` directory. Although the old `files` directory is now deprecated, if both directories are present, only the old `files` directory will be used for compatiblity.
2424

25+
You can revert back to the old behavior by defining `externalLinkTarget="_self"` in your in the `params` section of your `config.toml`.
26+
27+
2528
- {{% badge style="note" title=" " %}}Change{{% /badge %}} Absolute links prefixed with `http://` or `https://` are now opened in a separate browser tab.
2629

2730
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme now supports [Hugo's module system](https://gohugo.io/hugo-modules/).

layouts/partials/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
{{- if and (eq $outputFormat "html") .Site.Params.editURL $File }}
9191
{{- with $File.Path }}
9292
<div id="top-github-link">
93-
<a class="github-link" title='{{ T "Edit-this-page" }} (CTRL+ALT+w)' href="{{ $Site.Params.editURL }}{{ replace $File.Dir "\\" "/" }}{{ $File.LogicalName }}" target="blank">
93+
<a class="github-link" title='{{ T "Edit-this-page" }} (CTRL+ALT+w)' href="{{ $Site.Params.editURL }}{{ replace $File.Dir "\\" "/" }}{{ $File.LogicalName }}" target="_blank">
9494
<i class="fas fa-pen fa-fw"></i>
9595
</a>
9696
</div>

layouts/partials/shortcodes/button.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{{- end }}
1414
{{- else if and (eq (len $target) 0) (or (strings.HasPrefix $href "http://") (strings.HasPrefix $href "https://") ) }}
1515
{{- $target = "_blank" }}
16+
{{- if isset $context.Site.Params "externallinktarget" }}
17+
{{- $target = $context.Site.Params.externalLinkTarget }}
18+
{{- end }}
1619
{{- end }}
1720
{{- $title := .title | default ($content) | default ($style | T) }}
1821
{{- $title = trim $title " " }}
@@ -33,7 +36,7 @@
3336
{{- if $isButton }}
3437
<button{{ if $href }} onclick="{{ $href | safeJS }}"{{ end }}{{ if gt (len $type) 0 }} type="{{ $type }}"{{ end }}>
3538
{{- else }}
36-
<a{{ if $href }} href="{{ $href }}"{{ if gt (len $target) 0 }} target="{{ $target }}" rel="noopener"{{ end }}{{ end }}>
39+
<a{{ if $href }} href="{{ $href }}"{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}{{ end }}>
3740
{{- end }}
3841
{{- if and $icon (eq $iconposition "left") }}
3942
<i class="{{ $icon }}"></i>

layouts/partials/shortcodes/link.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
{{- $target := .target | default "" }}
77
{{- if and (eq (len $target) 0) (or (strings.HasPrefix $url "http://") (strings.HasPrefix $url "https://") ) }}
88
{{- $target = "_blank" }}
9+
{{- if isset $context.Page.Site.Params "externallinktarget" }}
10+
{{- $target = $context.Page.Site.Params.externalLinkTarget }}
11+
{{- end }}
912
{{- end -}}
10-
<a href="{{ $url | safeURL }}"{{ if $title }} title="{{ $title }}"{{ end }}{{ if gt (len $target) 0 }} target="{{ $target }}" rel="noopener"{{ end }}>{{ $content | safeHTML }}</a>
13+
<a href="{{ $url | safeURL }}"{{ if $title }} title="{{ $title }}"{{ end }}{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ $content | safeHTML }}</a>

0 commit comments

Comments
 (0)