Change figure shortcode to use relative paths as page resources

This commit is contained in:
Will Faught
2022-12-28 23:50:27 -08:00
parent c057d98eb3
commit 361e62d334
2 changed files with 9 additions and 1 deletions

View File

@@ -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 }}