Skip to content

Commit 0c941eb

Browse files
jin-liCaiJimmy
andauthored
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>
1 parent f13c478 commit 0c941eb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

config/_default/params.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ SortBy = "default"
7777
[imageProcessing]
7878
autoOrient = false
7979

80+
[imageProcessing.external]
81+
timeout = "5s"
82+
8083
[imageProcessing.content]
8184
widths = [800, 1600, 2400]
8285
enabled = true

layouts/_partials/helper/image.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,27 @@
1414
{{ if .Image }}
1515
{{ $url := urls.Parse .Image }}
1616
{{ $permalink := .Image }}
17-
{{ $resource := "" }}
17+
{{ $resource := dict
18+
"Resource" nil
19+
"Permalink" $permalink
20+
"Height" nil
21+
"Width" nil
22+
}}
1823
{{ $local := true }}
1924

2025
{{ if not (in (slice "https" "http") $url.Scheme) }}
2126
{{/* Local image */}}
2227
{{ $resource = .Resources.Get (printf "%s" (.Image | safeURL)) }}
2328
{{ else }}
2429
{{/* Remote image */}}
25-
{{ with try (resources.GetRemote $url) }}
30+
{{ with try (resources.GetRemote $url (dict "timeout" .Context.Site.Params.imageProcessing.external.timeout)) }}
2631
{{ with .Err }}
27-
{{ errorf "%s" . }}
32+
{{ warnf "Failed to fetch remote resource %q: %s" $url . }}
2833
{{ else with .Value }}
2934
{{ $resource = . }}
3035
{{ $local = false }}
3136
{{ else }}
32-
{{ errorf "Unable to get remote resource %q" $url }}
37+
{{ warnf "Unable to get remote resource %q" $url }}
3338
{{ end }}
3439
{{ end }}
3540
{{ end }}

0 commit comments

Comments
 (0)