diff --git a/layouts/partials/function/get-remote-image.html b/layouts/partials/function/get-remote-image.html new file mode 100644 index 00000000..986667ad --- /dev/null +++ b/layouts/partials/function/get-remote-image.html @@ -0,0 +1,19 @@ +{{- /* cache remote image locally */ -}} +{{- $resource := 0 -}} +{{- $isRemote := urls.Parse .Src | partial "function/is-url-remote.html" -}} + +{{- if $isRemote -}} + {{- with try (resources.GetRemote .Src) -}} + {{- with .Err -}} + {{- warnf "%s" . -}} + {{- else with .Value -}} + {{- if .ResourceType | eq "image" -}} + {{- /* placed remote image in public/images/remote/ */ -}} + {{- $resource = . | resources.Copy (add "/images/remote/" .Name) -}} + {{- end -}} + {{- else -}} + {{- warnf "Unable to get remote image %q" .Src -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- return $resource -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 29b82f66..10d17a49 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.17-8b402129" -}} +{{- .Scratch.Set "version" "v0.3.17-8212d6fd" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/image.html index db745d90..15cc3127 100644 --- a/layouts/partials/plugin/image.html +++ b/layouts/partials/plugin/image.html @@ -38,18 +38,9 @@ https://github.com/HEIGE-PCloud/DoIt/blob/main/layouts/partials/plugin/image.htm {{- $cacheRemote := .CacheRemote | default site.Params.image.cacheRemote | default false -}} {{- $optimise := .Optimise | default site.Params.image.optimise | default false -}} -{{- if not $resource | and $isRemote | and $cacheRemote -}} - {{- with try (resources.GetRemote .Src) -}} - {{- with .Err -}} - {{- warnf "%s" . -}} - {{- else with .Value -}} - {{- if .ResourceType | eq "image" -}} - {{- /* placed remote image in public/images/remote/ */ -}} - {{- $resource = . | resources.Copy (add "/images/remote/" .Name) -}} - {{- end -}} - {{- else -}} - {{- warnf "Unable to get remote image %q" .Src -}} - {{- end -}} +{{- if not $resource | and $cacheRemote -}} + {{- with partial "function/get-remote-image.html" (dict "Src" .Src) -}} + {{- $resource = . -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/plugin/link.html b/layouts/partials/plugin/link.html index a7ccd93e..0ca1019e 100644 --- a/layouts/partials/plugin/link.html +++ b/layouts/partials/plugin/link.html @@ -42,6 +42,12 @@ {{- end -}} {{- else -}} {{- $cardIcon := .CardIcon -}} + {{- if not $cardIcon -}} + {{- with partial "function/get-remote-image.html" (dict "Src" (add "https://favicon.im/" $url.Host)) -}} + {{- $cardIcon = .RelPermalink -}} + {{- end -}} + {{- end -}} + {{- $attrs := `class="cl-backdrop"` -}} {{- $attrs = printf ` style="--cl-bg-url: url(%v);"` (resources.Get "images/fixit.svg" | minify).RelPermalink | add $attrs -}}