mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
23 lines
953 B
HTML
23 lines
953 B
HTML
{{- /* cache remote image locally */ -}}
|
|
{{- $resource := 0 -}}
|
|
{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" ".avif" ".svg" -}}
|
|
{{- $suffixValid := (dict "Path" .Path "Suffixes" $suffixList | partial "function/suffix-validation.html") -}}
|
|
{{- /* maybe could add domain validation */ -}}
|
|
{{- $pass := $suffixValid | or .Pass -}}
|
|
|
|
{{- if $pass -}}
|
|
{{- with $remoteResource := resources.GetRemote .Path -}}
|
|
{{- with .Err -}}
|
|
{{- erroridf "error-get-remote-image" "%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 -}}
|
|
{{- else -}}
|
|
{{- erroridf "error-get-remote-image" "Unable to get remote image %q" .Path -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- return $resource -}}
|