mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-30 03:03:09 +00:00
Loop through favicon types for selection
* https://github.com/McShelby/hugo-theme-relearn/pull/553#discussion_r1213705852
This commit is contained in:
parent
4548d0162d
commit
b705e0bde4
1 changed files with 37 additions and 17 deletions
|
@ -1,26 +1,46 @@
|
||||||
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
|
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
|
||||||
{{- if or (fileExists "/static/images/favicon-light.svg") (fileExists "/static/images/favicon-dark.svg") }}
|
{{- $faviconMatch := false }}
|
||||||
|
{{- $svg := dict "ext" "svg" "type" "image/svg+xml" }}
|
||||||
|
{{- $png := dict "ext" "png" "type" "image/png" }}
|
||||||
|
{{- $ico := dict "ext" "ico" "type" "image/x-icon" }}
|
||||||
|
{{- $faviconTypes := slice $svg $png $ico }}
|
||||||
|
{{- range $faviconTypes }}
|
||||||
|
{{- if and
|
||||||
|
(eq $faviconMatch false)
|
||||||
|
(or
|
||||||
|
(fileExists (printf "/static/images/favicon-light.%s" .ext))
|
||||||
|
(fileExists (printf "/static/images/favicon-dark.%s"))
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
{{- $faviconMatch = true }}
|
||||||
{{/*
|
{{/*
|
||||||
Warning: IE and old browser versions do not support media queries necessary for the light & dark theme option.
|
Warning: IE and old browser versions do not support media queries necessary for the light & dark theme option.
|
||||||
If you have requirements to support IE and/or older browser versions, use one of the other options.
|
If you have requirements to support IE and/or older browser versions, use one of the other options.
|
||||||
Reference: https://caniuse.com/css-media-interaction
|
Reference: https://caniuse.com/css-media-interaction
|
||||||
*/}}
|
*/}}
|
||||||
{{- if (fileExists "/static/images/favicon-light.svg") }}
|
{{- if (fileExists (printf "/static/images/favicon-light.%s" .ext)) }}
|
||||||
<link href="{{ "images/favicon-light.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/svg+xml" media="(prefers-color-scheme: light)">
|
<link href="{{ printf "images/favicon-light.%s" .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="{{ .type }}" media="(prefers-color-scheme: light)">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if (fileExists "/static/images/favicon-dark.svg") }}
|
{{- if (fileExists (printf "/static/images/favicon-dark.%s" .ext)) }}
|
||||||
<link href="{{ "images/favicon-dark.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/svg+xml" media="(prefers-color-scheme: dark)">
|
<link href="{{ printf "images/favicon-dark.%s" .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="{{ .type }}" media="(prefers-color-scheme: dark)">
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- range $faviconTypes }}
|
||||||
|
{{- if and
|
||||||
|
(eq $faviconMatch false)
|
||||||
|
(fileExists (printf "/static/images/favicon.%s" .ext))
|
||||||
|
}}
|
||||||
|
{{- $faviconMatch = true }}
|
||||||
|
<link href="{{ printf "images/favicon.%s" .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="{{ .type }}">
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- range $faviconTypes }}
|
||||||
|
{{- if and
|
||||||
|
(eq $faviconMatch false)
|
||||||
|
(fileExists (printf "/static/images/logo.%s" .ext))
|
||||||
|
}}
|
||||||
|
{{- $faviconMatch := true }}
|
||||||
|
<link href="{{ printf "images/logo.%s" .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="{{ .type }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- else if (fileExists "/static/images/favicon.svg") }}
|
|
||||||
<link href="{{ "images/favicon.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/svg+xml">
|
|
||||||
{{- else if (fileExists "/static/images/favicon.png") }}
|
|
||||||
<link href="{{ "images/favicon.png" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/png">
|
|
||||||
{{- else if (fileExists "/static/images/favicon.ico") }}
|
|
||||||
<link href="{{ "images/favicon.ico" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/x-icon">
|
|
||||||
{{- else if (fileExists "/static/images/logo.svg") }}
|
|
||||||
<link href="{{ "images/logo.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/svg+xml">
|
|
||||||
{{- else if (fileExists "/static/images/logo.png") }}
|
|
||||||
<link href="{{ "images/logo.png" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/png">
|
|
||||||
{{- else if (fileExists "/static/images/logo.ico") }}
|
|
||||||
<link href="{{ "images/logo.ico" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/x-icon">
|
|
||||||
{{- end }}
|
{{- end }}
|
Loading…
Reference in a new issue