forked from matcornic/hugo-theme-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
favicon: add light & dark option for OS's prefered color scheme matco…
- Loading branch information
Showing
3 changed files
with
23 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,32 @@ | ||
{{- $assetBusting := not .Site.Params.disableAssetsBusting }} | ||
{{- $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" }} | ||
{{- $svg := dict "ext" "svg" "type" "type=\"image/svg+xml\"" }} | ||
{{- $png := dict "ext" "png" "type" "type=\"image/png\"" }} | ||
{{- $ico := dict "ext" "ico" "type" "type=\"image/x-icon\" sizes=\"any\"" }} | ||
{{- $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 }} | ||
{{$c:=""}}{{/* | ||
{{- $faviconNames := slice "favicon" "logo" }} | ||
{{- range $faviconNames }} | ||
{{- $faviconName := . }} | ||
{{- range $faviconTypes }} | ||
{{- if fileExists (printf "/static/images/%s.%s" $faviconName .ext) }} | ||
{{- $faviconMatch = true }} | ||
<link href="{{ printf "images/%s.%s" $faviconName .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" {{ .type | safeHTMLAttr }}> | ||
{{- end }} | ||
{{- $c:="" }}{{/* | ||
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. | ||
Reference: https://caniuse.com/css-media-interaction | ||
*/}} | ||
{{- if (fileExists (printf "/static/images/favicon-light.%s" .ext)) }} | ||
<link href="{{ printf "images/favicon-light.%s" .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="{{ .type }}" media="(prefers-color-scheme: light)"> | ||
{{- if (fileExists (printf "/static/images/%s-light.%s" $faviconName .ext)) }} | ||
{{- $faviconMatch = true }} | ||
<link href="{{ printf "images/%s-light.%s" $faviconName .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" {{ .type | safeHTMLAttr }} media="(prefers-color-scheme: light)"> | ||
{{- end }} | ||
{{- if (fileExists (printf "/static/images/favicon-dark.%s" .ext)) }} | ||
<link href="{{ printf "images/favicon-dark.%s" .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="{{ .type }}" media="(prefers-color-scheme: dark)"> | ||
{{- if (fileExists (printf "/static/images/%s-dark.%s" $faviconName .ext)) }} | ||
{{- $faviconMatch = true }} | ||
<link href="{{ printf "images/%s-dark.%s" $faviconName .ext | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" {{ .type | safeHTMLAttr }} 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 }}"> | ||
{{- if $faviconMatch }} | ||
{{- break }} | ||
{{- end }} | ||
{{- end }} |