favicon: publish resource #1023
Some checks are pending
docs-build-deployment / Run deploy (push) Waiting to run
docs-build / Run build (push) Waiting to run

if icon found in assets
and DRY code
This commit is contained in:
Sören Weber 2025-02-15 03:50:14 +01:00
parent 52e6df6cdf
commit 59e60d6bc9
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 17 additions and 21 deletions

View file

@ -5,29 +5,25 @@
{{- $ico := dict "ext" "ico" "type" "type=\"image/x-icon\" sizes=\"any\"" }}
{{- $faviconTypes := slice $svg $png $ico }}
{{- $faviconNames := slice "favicon" "logo" }}
{{- $normal := dict "suffix" "" "media" "" }}
{{- $light := dict "suffix" "-light" "media" " media=\"(prefers-color-scheme: light\")" }}
{{- $dark := dict "suffix" "-dark" "media" " media=\"(prefers-color-scheme: dark\")" }}
{{- $faviconVariants := slice $normal $light $dark }}
{{- range $faviconNames }}
{{- $faviconName := . }}
{{- range $faviconTypes }}
{{- if or
(resources.Get (printf "/images/%s.%s" $faviconName .ext))
(fileExists (printf "/static/images/%s.%s" $faviconName .ext))
}}
{{- $faviconMatch = true }}
<link href="{{ printf "images/%s.%s" $faviconName .ext | relURL }}{{ $assetBusting }}" rel="icon" {{ .type | safeHTMLAttr }}>
{{- end }}
{{- if or
(resources.Get (printf "/images/%s-light.%s" $faviconName .ext))
(fileExists (printf "/static/images/%s-light.%s" $faviconName .ext))
}}
{{- $faviconMatch = true }}
<link href="{{ printf "images/%s-light.%s" $faviconName .ext | relURL }}{{ $assetBusting }}" rel="icon" {{ .type | safeHTMLAttr }} media="(prefers-color-scheme: light)">
{{- end }}
{{- if or
(resources.Get (printf "/images/%s-dark.%s" $faviconName .ext))
(fileExists (printf "/static/images/%s-dark.%s" $faviconName .ext))
}}
{{- $faviconMatch = true }}
<link href="{{ printf "images/%s-dark.%s" $faviconName .ext | relURL }}{{ $assetBusting }}" rel="icon" {{ .type | safeHTMLAttr }} media="(prefers-color-scheme: dark)">
{{- $faviconType := . }}
{{- range $faviconVariants }}
{{- $faviconVariant := . }}
{{- with (resources.Get (printf "/images/%s%s.%s" $faviconName $faviconVariant.suffix $faviconType.ext)) }}
{{- $faviconMatch = true }}
<link href="{{ .RelPermalink }}{{ $assetBusting }}" rel="icon" {{ $faviconType.type | safeHTMLAttr }}{{ $faviconVariant.media | safeHTMLAttr }}>
{{- else }}
{{- if (fileExists (printf "/static/images/%s%s.%s" $faviconName $faviconVariant.suffix $faviconType.ext)) }}
{{- $faviconMatch = true }}
<link href="{{ printf "images/%s%s.%s" $faviconName $faviconVariant.suffix $faviconType.ext | relURL }}{{ $assetBusting }}" rel="icon" {{ $faviconType.type | safeHTMLAttr }}{{ $faviconVariant.media | safeHTMLAttr }}>
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if $faviconMatch }}

View file

@ -1 +1 @@
7.3.2+0a3121be8f0b49511eb20df9d2839e10a817fd75
7.3.2+52e6df6cdf5bc048ceab918c10d6c94a851569ec