Added newtab option to file shortcode.

This commit is contained in:
Fredrik Jonsson 2020-11-25 08:55:57 +01:00
commit 02efe4fdde
2 changed files with 7 additions and 5 deletions

View file

@ -476,8 +476,9 @@ Creates a link to a file in static or in assets directory.
Possible parameters are:
* class
* name
* newtab (default false)
* src
* text
### Search

View file

@ -1,11 +1,12 @@
{{ $class := .Get "class" -}}
{{ $name := .Get "name" -}}
{{ $newtab := .Get "newtab" | default false -}}
{{ $src := .Get "src" -}}
{{ $text := .Get "text" -}}
{{ if and $src (fileExists (add "/assets" $src)) -}}
{{ $original := resources.Get $src -}}
{{ $src = $original.RelPermalink -}}
{{ end -}}
{{ if not $name -}}
{{ $name = path.Base $src -}}
{{ if not $text -}}
{{ $text = path.Base $src -}}
{{ end -}}
<a class="file{{ with $class }} {{ . }}{{ end }}" href="{{ $src }}">{{ $name }}</a>
<a class="file{{ with $class }} {{ . }}{{ end }}" href="{{ $src }}"{{ if $newtab }} target="_blank" rel="noopener noreferrer"{{ end }}>{{ $text }}</a>