Added new file shortcode and added better checks in figure and img shortcodes.
This commit is contained in:
parent
507394c93d
commit
46595e5ae9
4 changed files with 30 additions and 5 deletions
13
README.md
13
README.md
|
|
@ -455,7 +455,7 @@ Possible parameters are:
|
||||||
* caption (only figure)
|
* caption (only figure)
|
||||||
* class
|
* class
|
||||||
* height
|
* height
|
||||||
* link (only figure)
|
* link
|
||||||
* size (only works if image is inside /assets dir)
|
* size (only works if image is inside /assets dir)
|
||||||
* src
|
* src
|
||||||
* title (only figure)
|
* 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.
|
* 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
|
### Search
|
||||||
|
|
||||||
Creates a search page for the site, [see more above](#search).
|
Creates a search page for the site, [see more above](#search).
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
{{ $maxwidth := .Site.Params.imageMaxWidth -}}
|
{{ $maxwidth := .Site.Params.imageMaxWidth -}}
|
||||||
{{ $realwidth := 0 -}}
|
{{ $realwidth := 0 -}}
|
||||||
{{ $realheight := 0 -}}
|
{{ $realheight := 0 -}}
|
||||||
{{ if (fileExists (add "/assets" $src)) -}}
|
{{ if and $src (fileExists (add "/assets" $src)) -}}
|
||||||
{{ $original := resources.Get $src -}}
|
{{ $original := resources.Get $src -}}
|
||||||
{{ if $size -}}
|
{{ if $size -}}
|
||||||
{{ $image := $original.Resize $size -}}
|
{{ $image := $original.Resize $size -}}
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
{{ $realwidth = $original.Width -}}
|
{{ $realwidth = $original.Width -}}
|
||||||
{{ $realheight = $original.Height -}}
|
{{ $realheight = $original.Height -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ else if (fileExists (add "/static" $src)) -}}
|
{{ else if and $src (fileExists (add "/static" $src)) -}}
|
||||||
{{ with (imageConfig (add "/static" $src)) -}}
|
{{ with (imageConfig (add "/static" $src)) -}}
|
||||||
{{ $realwidth = .Width -}}
|
{{ $realwidth = .Width -}}
|
||||||
{{ $realheight = .Height -}}
|
{{ $realheight = .Height -}}
|
||||||
|
|
|
||||||
11
layouts/shortcodes/file.html
Normal file
11
layouts/shortcodes/file.html
Normal file
|
|
@ -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 -}}
|
||||||
|
<a class="file{{ with $class }} {{ . }}{{ end }}" href="{{ $src }}">{{ $name }}</a>
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
{{ $alt := .Get "alt" -}}
|
{{ $alt := .Get "alt" -}}
|
||||||
{{ $class := .Get "class" -}}
|
{{ $class := .Get "class" -}}
|
||||||
{{ $height := .Get "height" -}}
|
{{ $height := .Get "height" -}}
|
||||||
|
{{ $link := .Get "link" -}}
|
||||||
{{ $size := .Get "size" -}}
|
{{ $size := .Get "size" -}}
|
||||||
{{ $src := .Get "src" -}}
|
{{ $src := .Get "src" -}}
|
||||||
{{ $width := .Get "width" -}}
|
{{ $width := .Get "width" -}}
|
||||||
{{ $maxwidth := .Site.Params.imageMaxWidth -}}
|
{{ $maxwidth := .Site.Params.imageMaxWidth -}}
|
||||||
{{ $realwidth := 0 -}}
|
{{ $realwidth := 0 -}}
|
||||||
{{ $realheight := 0 -}}
|
{{ $realheight := 0 -}}
|
||||||
{{ if (fileExists (add "/assets" $src)) -}}
|
{{ if and $src (fileExists (add "/assets" $src)) -}}
|
||||||
{{ $original := resources.Get $src -}}
|
{{ $original := resources.Get $src -}}
|
||||||
{{ if $size -}}
|
{{ if $size -}}
|
||||||
{{ $image := $original.Resize $size -}}
|
{{ $image := $original.Resize $size -}}
|
||||||
|
|
@ -19,7 +20,7 @@
|
||||||
{{ $realwidth = $original.Width -}}
|
{{ $realwidth = $original.Width -}}
|
||||||
{{ $realheight = $original.Height -}}
|
{{ $realheight = $original.Height -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ else if (fileExists (add "/static" $src)) -}}
|
{{ else if and $src (fileExists (add "/static" $src)) -}}
|
||||||
{{ with (imageConfig (add "/static" $src)) -}}
|
{{ with (imageConfig (add "/static" $src)) -}}
|
||||||
{{ $realwidth = .Width -}}
|
{{ $realwidth = .Width -}}
|
||||||
{{ $realheight = .Height -}}
|
{{ $realheight = .Height -}}
|
||||||
|
|
@ -47,4 +48,6 @@
|
||||||
{{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}}
|
{{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}}
|
||||||
{{ $height = (math.Round $height) -}}
|
{{ $height = (math.Round $height) -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
{{ with $link }}<a class="image-link" href="{{ . }}">{{ end -}}
|
||||||
<img class="image{{ with $class }} {{ . }}{{ end }}" src="{{ $src }}"{{ with $alt }} alt="{{ . }}"{{ end }}{{ with $width }} width="{{ . }}"{{ end }}{{ with $height }} height="{{ . }}"{{ end }}>
|
<img class="image{{ with $class }} {{ . }}{{ end }}" src="{{ $src }}"{{ with $alt }} alt="{{ . }}"{{ end }}{{ with $width }} width="{{ . }}"{{ end }}{{ with $height }} height="{{ . }}"{{ end }}>
|
||||||
|
{{- if $link }}</a>{{ end }}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue