Files
FixIt/layouts/partials/function/get-remote-image.html
T

19 lines
734 B
HTML

{{- /* cache remote image locally */ -}}
{{- $resource := 0 -}}
{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" ".avif" ".svg" -}}
{{- $suffixValid := (dict "Path" . "Suffixes" $suffixList | partial "function/suffix-validation.html") -}}
{{- if $suffixValid -}}
{{- with $remoteResource := resources.GetRemote . -}}
{{- with .Err -}}
{{- warnf "%s" . -}}
{{ else }}
{{- if eq $remoteResource.ResourceType "image" -}}
{{- /* placed remote image in public/images/remote/ */ -}}
{{- $resource = $remoteResource | resources.Copy (add "/images/remote/" $remoteResource.Name) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- return $resource -}}