Feat: get link favicon from remote by https://favicon.im/

This commit is contained in:
Cell
2025-03-12 12:31:11 +08:00
parent 8212d6fd02
commit 6c7145c311
4 changed files with 29 additions and 13 deletions
@@ -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 -}}
+1 -1
View File
@@ -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" . -}}
+3 -12
View File
@@ -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 -}}
+6
View File
@@ -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 -}}
<span {{ $attrs | safeHTMLAttr }}></span>