diff --git a/README.md b/README.md index 714c967..9b991bd 100644 --- a/README.md +++ b/README.md @@ -455,7 +455,7 @@ Possible parameters are: * caption (only figure) * class * height -* link (only figure) +* link * size (only works if image is inside /assets dir) * src * title (only figure) @@ -469,6 +469,17 @@ Only "src" is none optional but you really should set "alt" as well. * If only width or only height is set the other value will be proportionally calculated. +### File + +Creates a link to a file in static or in assets directory. + +Possible parameters are: + +* class +* name +* src + + ### Search Creates a search page for the site, [see more above](#search). diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index ded947a..e3c16bc 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -12,7 +12,7 @@ {{ $maxwidth := .Site.Params.imageMaxWidth -}} {{ $realwidth := 0 -}} {{ $realheight := 0 -}} -{{ if (fileExists (add "/assets" $src)) -}} +{{ if and $src (fileExists (add "/assets" $src)) -}} {{ $original := resources.Get $src -}} {{ if $size -}} {{ $image := $original.Resize $size -}} @@ -24,7 +24,7 @@ {{ $realwidth = $original.Width -}} {{ $realheight = $original.Height -}} {{ end -}} -{{ else if (fileExists (add "/static" $src)) -}} +{{ else if and $src (fileExists (add "/static" $src)) -}} {{ with (imageConfig (add "/static" $src)) -}} {{ $realwidth = .Width -}} {{ $realheight = .Height -}} diff --git a/layouts/shortcodes/file.html b/layouts/shortcodes/file.html new file mode 100644 index 0000000..3c76699 --- /dev/null +++ b/layouts/shortcodes/file.html @@ -0,0 +1,11 @@ +{{ $class := .Get "class" -}} +{{ $name := .Get "name" -}} +{{ $src := .Get "src" -}} +{{ if and $src (fileExists (add "/assets" $src)) -}} + {{ $original := resources.Get $src -}} + {{ $src = $original.RelPermalink -}} +{{ end -}} +{{ if not $name -}} + {{ $name = path.Base $src -}} +{{ end -}} +{{ $name }} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html index 98a07d3..e7caff2 100644 --- a/layouts/shortcodes/img.html +++ b/layouts/shortcodes/img.html @@ -1,13 +1,14 @@ {{ $alt := .Get "alt" -}} {{ $class := .Get "class" -}} {{ $height := .Get "height" -}} +{{ $link := .Get "link" -}} {{ $size := .Get "size" -}} {{ $src := .Get "src" -}} {{ $width := .Get "width" -}} {{ $maxwidth := .Site.Params.imageMaxWidth -}} {{ $realwidth := 0 -}} {{ $realheight := 0 -}} -{{ if (fileExists (add "/assets" $src)) -}} +{{ if and $src (fileExists (add "/assets" $src)) -}} {{ $original := resources.Get $src -}} {{ if $size -}} {{ $image := $original.Resize $size -}} @@ -19,7 +20,7 @@ {{ $realwidth = $original.Width -}} {{ $realheight = $original.Height -}} {{ end -}} -{{ else if (fileExists (add "/static" $src)) -}} +{{ else if and $src (fileExists (add "/static" $src)) -}} {{ with (imageConfig (add "/static" $src)) -}} {{ $realwidth = .Width -}} {{ $realheight = .Height -}} @@ -47,4 +48,6 @@ {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} {{ $height = (math.Round $height) -}} {{ end -}} +{{ with $link }}{{ end -}} {{ . }} +{{- if $link }}{{ end }}