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:
lijin
2026-03-08 13:18:21 +01:00
committed by GitHub
co-authored by Jimmy Cai
parent f13c478718
commit 0c941ebb04
2 changed files with 12 additions and 4 deletions
+3
View File
@@ -77,6 +77,9 @@ SortBy = "default"
[imageProcessing] [imageProcessing]
autoOrient = false autoOrient = false
[imageProcessing.external]
timeout = "5s"
[imageProcessing.content] [imageProcessing.content]
widths = [800, 1600, 2400] widths = [800, 1600, 2400]
enabled = true enabled = true
+9 -4
View File
@@ -14,7 +14,12 @@
{{ if .Image }} {{ if .Image }}
{{ $url := urls.Parse .Image }} {{ $url := urls.Parse .Image }}
{{ $permalink := .Image }} {{ $permalink := .Image }}
{{ $resource := "" }} {{ $resource := dict
"Resource" nil
"Permalink" $permalink
"Height" nil
"Width" nil
}}
{{ $local := true }} {{ $local := true }}
{{ if not (in (slice "https" "http") $url.Scheme) }} {{ if not (in (slice "https" "http") $url.Scheme) }}
@@ -22,14 +27,14 @@
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }} {{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
{{ else }} {{ else }}
{{/* Remote image */}} {{/* Remote image */}}
{{ with try (resources.GetRemote $url) }} {{ with try (resources.GetRemote $url (dict "timeout" .Context.Site.Params.imageProcessing.external.timeout)) }}
{{ with .Err }} {{ with .Err }}
{{ errorf "%s" . }} {{ warnf "Failed to fetch remote resource %q: %s" $url . }}
{{ else with .Value }} {{ else with .Value }}
{{ $resource = . }} {{ $resource = . }}
{{ $local = false }} {{ $local = false }}
{{ else }} {{ else }}
{{ errorf "Unable to get remote resource %q" $url }} {{ warnf "Unable to get remote resource %q" $url }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}