feat: workaround Hugo v0.81 error on Windows with remote figure

Hugo v0.81 on Windows will error when figure destination is a remote URL such that we have `resources.Get (path.Join "media" <URL>)`.

See https://github.com/wowchemy/wowchemy-hugo-modules/discussions/2205
This commit is contained in:
George Cushen committed 2021-03-03 11:14:50 +00:00
1 parent 3952bfc85c
commit 5529404d19
1 file changed
+8 -3
+8 -3
View File
@@ -4,6 +4,7 @@
such as Callout, without the HTML being rendered as a Markdown code block. */}}
{{ $destination := .Get "src" }}
{{ $is_remote := strings.HasPrefix $destination "http" }}
{{ $caption := .Get "caption" | default (.Get "title") | default "" }}{{/* Support legacy `title` option. */}}
{{ $zoom := eq (.Get "lightbox" | default "true") "true" }}
{{ $id := anchorize (.Get "id" | default ($caption | plainify)) }}
@@ -12,9 +13,13 @@
{{ if eq (.Get "theme" | lower) "light" }}{{ $img_class = printf "%s img-light" $img_class }}{{end}}
{{ if eq (.Get "theme" | lower) "dark" }}{{ $img_class = printf "%s img-dark" $img_class }}{{end}}
{{- $img := (.Page.Resources.ByType "image").GetMatch $destination -}}
{{- if not $img -}}
{{- $img = resources.Get (path.Join "media" $destination) -}}
{{/* Workaround Hugo v0.81 error on Windows when `resources.Get (path.Join "media" <URL>)` */}}
{{- $img := "" -}}
{{- if not $is_remote -}}
{{- $img = (.Page.Resources.ByType "image").GetMatch $destination -}}
{{- if not $img -}}
{{- $img = resources.Get (path.Join "media" $destination) -}}
{{- end -}}
{{- end -}}
<figure {{ with .Get "class" }}class="{{.}}"{{ end }} {{ with $id }}id="figure-{{ . }}"{{ end }}>