Change figure shortcode to use relative paths as page resources

master
Will Faught 3 years ago
parent c057d98eb3
commit 361e62d334

@ -455,6 +455,7 @@ The `paige/figure` shortcode provides a figure with a centered image and an opti
The image and caption can optionally be displayed inline instead of centered.
The image has optional alt, title, width, and height attributes,
and can optionally be wrapped in an anchor. Only the image source parameter is required.
If the image source is a relative path, it is assumed to be a page resource.
These are the named parameters with positions, listed in the order of their positions:

@ -3,7 +3,14 @@
{{ with $link }}
<a href="{{ . }}">
{{ end }}
<img{{ with (.Get 4 | default (.Get `alt`)) }} alt="{{ . }}"{{ end }} class="figure-img img-fluid"{{ with .Get `height` }} height="{{ . }}"{{ end }} src="{{ .Get 0 | default (.Get `src`) }}"{{ with (.Get 3 | default (.Get `title`)) }} title="{{ . }}"{{ end }}{{ with .Get `width` }} width="{{ . }}"{{ end }}>
{{ $src := .Get 0 | default (.Get `src`) }}
{{ $url := urls.Parse $src }}
{{ if and (not $url.IsAbs) (not (hasPrefix $url.Path "/")) }}
{{ with .Page.Resources.GetMatch $src }}
{{ $src = .RelPermalink }}
{{ end }}
{{ end }}
<img{{ with (.Get 4 | default (.Get `alt`)) }} alt="{{ . }}"{{ end }} class="figure-img img-fluid"{{ with .Get `height` }} height="{{ . }}"{{ end }} src="{{ $src }}"{{ with (.Get 3 | default (.Get `title`)) }} title="{{ . }}"{{ end }}{{ with .Get `width` }} width="{{ . }}"{{ end }}>
{{ if $link }}
</a>
{{ end }}

Loading…
Cancel
Save