From 0d6af76f060a3654d1ed4ba70aa87d521a919786 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sun, 19 Jul 2026 15:33:15 +0800 Subject: [PATCH] feat(layouts): add timeout and cache key options to get-remote-image partial --- layouts/_partials/function/get-remote-image.html | 5 ++++- layouts/_partials/function/get-remote-json.html | 2 +- layouts/_partials/init/index.html | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/layouts/_partials/function/get-remote-image.html b/layouts/_partials/function/get-remote-image.html index e93c9978..2ea5d5e3 100644 --- a/layouts/_partials/function/get-remote-image.html +++ b/layouts/_partials/function/get-remote-image.html @@ -1,9 +1,12 @@ {{- /* cache remote image locally */ -}} {{- $resource := 0 -}} +{{- $options := .OPTIONS | default dict -}} +{{- $cacheKey := print .Src (now.Format "2006-01-02") -}} +{{- $options = $options | merge (dict "key" $cacheKey "timeout" "3s") -}} {{- $isRemote := urls.Parse .Src | partial "function/is-url-remote.html" -}} {{- if $isRemote -}} - {{- with try (resources.GetRemote .Src) -}} + {{- with try (resources.GetRemote .Src $options) -}} {{- with .Err -}} {{- warnidf "warning-remote-image" "%s" . -}} {{- else with .Value -}} diff --git a/layouts/_partials/function/get-remote-json.html b/layouts/_partials/function/get-remote-json.html index b690ae3c..bd48270b 100644 --- a/layouts/_partials/function/get-remote-json.html +++ b/layouts/_partials/function/get-remote-json.html @@ -7,7 +7,7 @@ {{- end -}} {{- $cacheKey := print $url (now.Format "2006-01-02") -}} -{{- $options = $options | merge (dict "key" $cacheKey) -}} +{{- $options = $options | merge (dict "key" $cacheKey "timeout" "3s") -}} {{- with try (resources.GetRemote $url $options) -}} {{- with .Err -}} {{- erroridf "error-get-remote-json" "%s" . -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index d8813d7d..03e41501 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v1.0.0-mrrceo88" -}} +{{- hugo.Store.Set "version" "v1.0.0-mrrhb8pg" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}