Hello. I’m using a Github repository in conjunction with Cloudflare Pages to deploy my website.
I have a few images on a page I’m setting up, each are configured slightly differently for various reasons. For some reason, the one that utilises ‘.Parent.Resources.GetMatch’ isn’t showing at all on the deployed version of the website, however it appears fine on the localhost version of the website. I’ve also checked that the asset actually exists on the live directory, and the asset is accessible, so I’m not sure why it wouldn’t be ‘finding’ it.
Here’s the code I’m using.
This is the one that doesn’t work on live:
{{- $image := .Parent.Resources.GetMatch "about-bubble.webp" -}}
{{- /* The following is is used as a fallback if the image is not found or if it's a GIF. */ -}}
{{- $default := printf "<img src=\"%s\"alt=\"%s\" title=\"%s\" />" (.Params.Image | safeURL) $.Title -}}
{{- if $image -}}
{{- $imageOriginalWidth := $image.Width -}}
{{- $sizes := slice 180 -}}
{{- $srcset := slice -}}
{{- $sizestag := slice -}}
{{- range $sizes -}}
{{- if lt (mul . 1.2) $imageOriginalWidth -}}
{{- $thumb := $image.Resize (printf "%dx webp q65" .) -}}
{{- $srcset = $srcset | append (printf ("%s %dw") $thumb.RelPermalink . ) -}}
{{- $sizestag = $sizestag | append (printf ("(max-width: %dpx) 100vw") . ) -}}
{{- end -}}
{{- end -}}
{{- if ne (len $srcset) 3 -}}
{{- $thumb := $image.Resize (printf "%dx webp q65" $imageOriginalWidth) -}}
{{- $srcset = $srcset | append (printf ("%s %dw") $thumb.RelPermalink $imageOriginalWidth ) -}}
{{- $sizestag = $sizestag | append (printf ("%dpx") $imageOriginalWidth ) -}}
{{- end -}}
<figure class="bubble-mask">
<img
src="{{ $image.RelPermalink }}"
class="bubble-image"
alt="Photo of Charlie & Emily"
{{- if gt (len $srcset) 0 -}}
{{- (printf " srcset=\"%s\"" (delimit $srcset ", ")) | safeHTMLAttr -}}
{{- (printf " sizes=\"%s\"" (delimit $sizestag ", ")) | safeHTMLAttr -}}
{{- end -}}
/>
</figure>
{{- end -}}
However, this code works fine on both live and my local. The only difference is line 1 and the number of slices I’m generating for responsive images:
{{- $image := .Page.Resources.GetMatch .Params.Image -}}
{{- /* The following is is used as a fallback if the image is not found or if it's a GIF. */ -}}
{{- $default := printf "<img src=\"%s\"alt=\"%s\" title=\"%s\" />" (.Params.Image | safeURL) $.Title -}}
{{- if $image -}}
{{- $imageOriginalWidth := $image.Width -}}
{{- $sizes := slice 480 540 720 960 -}}
{{- $srcset := slice -}}
{{- $sizestag := slice -}}
{{- range $sizes -}}
{{- if lt (mul . 1.2) $imageOriginalWidth -}}
{{- $thumb := $image.Resize (printf "%dx webp q100" .) -}}
{{- $srcset = $srcset | append (printf ("%s %dw") $thumb.RelPermalink . ) -}}
{{- $sizestag = $sizestag | append (printf ("(max-width: %dpx) 100vw") . ) -}}
{{- end -}}
{{- end -}}
{{- if ne (len $srcset) 3 -}}
{{- $thumb := $image.Resize (printf "%dx webp q100" $imageOriginalWidth) -}}
{{- $srcset = $srcset | append (printf ("%s %dw") $thumb.RelPermalink $imageOriginalWidth ) -}}
{{- $sizestag = $sizestag | append (printf ("%dpx") $imageOriginalWidth ) -}}
{{- end -}}
<figure class="bubble-mask">
<img
src="{{ $image.RelPermalink }}"
class="bubble-image"
alt="{{ .Title }}"
{{- if gt (len $srcset) 0 -}}
{{- (printf " srcset=\"%s\"" (delimit $srcset ", ")) | safeHTMLAttr -}}
{{- (printf " sizes=\"%s\"" (delimit $sizestag ", ")) | safeHTMLAttr -}}
{{- end -}}
/>
</figure>
{{- end -}}