Shortcodes for figure and gallery
This commit is contained in:
parent
ee6c0266e4
commit
545ae028ff
|
@ -1,23 +1,28 @@
|
|||
{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get "img")) }}
|
||||
{{ $img := .Get "img" }}
|
||||
{{ $caption := .Get "caption" }}
|
||||
{{ $command := .Get "command" }}
|
||||
{{ $options := .Get "options" }}
|
||||
|
||||
{{ $original := .Page.Resources.GetMatch (printf "*%s*" $img) }}
|
||||
{{ $new := "" }}
|
||||
|
||||
{{ if eq (.Get "command") "Fit" }}
|
||||
{{ $new = $original.Fit (.Get "options") }}
|
||||
{{ else if eq (.Get "command") "Fill" }}
|
||||
{{ $new = $original.Fill (.Get "options") }}
|
||||
{{ else if eq (.Get "command") "Resize" }}
|
||||
{{ $new = $original.Resize (.Get "options") }}
|
||||
{{ else if eq (.Get "command") "Original" }}
|
||||
{{ if eq $command "Fit" }}
|
||||
{{ $new = $original.Fit $options }}
|
||||
{{ else if eq $command "Fill" }}
|
||||
{{ $new = $original.Fill $options }}
|
||||
{{ else if eq $command "Resize" }}
|
||||
{{ $new = $original.Resize $options }}
|
||||
{{ else if eq $command "Original" }}
|
||||
{{ $new = $original }}
|
||||
{{ else }}
|
||||
{{ errorf "Invalid image processing command: Must be one of Fit, Fill, Resize, Original." }}
|
||||
{{ end }}
|
||||
|
||||
<figure role="group" aria-describedby="caption-{{ (.Get "caption") | md5 }}">
|
||||
<figure role="group" aria-describedby="caption-{{ $caption | md5 }}">
|
||||
<a href="{{ $original.Permalink }}" class="img-link">
|
||||
<img src="{{ $new.Permalink }}">
|
||||
</a>
|
||||
<figcaption id="caption-{{ (.Get "caption") | md5 }}">
|
||||
{{ (.Get "caption") | markdownify }}
|
||||
<figcaption id="caption-{{ $caption | md5 }}">
|
||||
{{ $caption | markdownify }}
|
||||
</figcaption>
|
||||
</figure>
|
||||
|
|
29
layouts/shortcodes/gallery.html
Normal file
29
layouts/shortcodes/gallery.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
{{ $command := .Get "command" }}
|
||||
{{ $options := .Get "options" }}
|
||||
|
||||
{{ with .Page.Resources.ByType "image" }}
|
||||
{{ range . }}
|
||||
|
||||
{{ $original := . }}
|
||||
{{ $new := "" }}
|
||||
|
||||
{{ if eq $command "Fit" }}
|
||||
{{ $new = $original.Fit $options }}
|
||||
{{ else if eq $command "Fill" }}
|
||||
{{ $new = $original.Fill $options }}
|
||||
{{ else if eq $command "Resize" }}
|
||||
{{ $new = $original.Resize $options }}
|
||||
{{ else if eq $command "Original" }}
|
||||
{{ $new = $original }}
|
||||
{{ else }}
|
||||
{{ errorf "Invalid image processing command: Must be one of Fit, Fill, Resize, Original." }}
|
||||
{{ end }}
|
||||
|
||||
<div class="gallery">
|
||||
<a href="{{ $original.Permalink }}" class="img-link">
|
||||
<img src="{{ $new.Permalink }}">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user