fix: skip inaccessible images to avoid build failure (#1301)
* skip inaccessible images to avoid build failure * undo changes to $result and $local * fix: initialize $resource as a dictionary instead of an empty string * feat: add external image processing timeout configuration --------- Co-authored-by: Jimmy Cai <jimmy@cai.im>
This commit is contained in:
@@ -77,6 +77,9 @@ SortBy = "default"
|
||||
[imageProcessing]
|
||||
autoOrient = false
|
||||
|
||||
[imageProcessing.external]
|
||||
timeout = "5s"
|
||||
|
||||
[imageProcessing.content]
|
||||
widths = [800, 1600, 2400]
|
||||
enabled = true
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
{{ if .Image }}
|
||||
{{ $url := urls.Parse .Image }}
|
||||
{{ $permalink := .Image }}
|
||||
{{ $resource := "" }}
|
||||
{{ $resource := dict
|
||||
"Resource" nil
|
||||
"Permalink" $permalink
|
||||
"Height" nil
|
||||
"Width" nil
|
||||
}}
|
||||
{{ $local := true }}
|
||||
|
||||
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
||||
@@ -22,14 +27,14 @@
|
||||
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
|
||||
{{ else }}
|
||||
{{/* Remote image */}}
|
||||
{{ with try (resources.GetRemote $url) }}
|
||||
{{ with try (resources.GetRemote $url (dict "timeout" .Context.Site.Params.imageProcessing.external.timeout)) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "%s" . }}
|
||||
{{ warnf "Failed to fetch remote resource %q: %s" $url . }}
|
||||
{{ else with .Value }}
|
||||
{{ $resource = . }}
|
||||
{{ $local = false }}
|
||||
{{ else }}
|
||||
{{ errorf "Unable to get remote resource %q" $url }}
|
||||
{{ warnf "Unable to get remote resource %q" $url }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user