Move favicons to seperate partial so it can use partialCached. Remove realfavicongenerator setting and autodetect favicon files instead.

This commit is contained in:
Fredrik Jonsson 2024-11-25 15:39:40 +01:00
commit 2bea24168e
3 changed files with 20 additions and 9 deletions

View file

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width">
<title>{{ block "title" . }}{{ .Title }} – {{ site.Title }}{{ end }}</title>
{{ partial "meta.html" . }}
{{ partialCached "favicons.html" . }}
{{ partialCached "styles.html" . }}
{{ partial "meta_json_ld.html" . }}
{{ partial "scripts.html" . }}

View file

@ -0,0 +1,17 @@
{{ if fileExists (path.Join "/static" "apple-touch-icon.png") -}}
<link rel="apple-touch-icon" href="{{ "apple-touch-icon.png" | relURL }}">
{{ end -}}
{{ if fileExists (path.Join "/static" "favicon.svg") -}}
<link rel="icon" type="image/svg+xml" href="{{ "favicon.svg" | relURL }}">
{{ end -}}
{{ if fileExists (path.Join "/static" "site.webmanifest") -}}
<link rel="manifest" href="{{ "site.webmanifest" | relURL }}">
{{ end -}}
{{ $favname := "" -}}
{{ $favsizes := slice "128x128" "96x96" "48x48" "32x32" "16x16" -}}
{{ range $favsizes -}}
{{ $favname = (printf "favicon-%s.png" .) -}}
{{ if fileExists (path.Join "/static" $favname) -}}
<link rel="icon" type="image/png" {{ printf "sizes=%q" . | safeHTMLAttr }} href="{{ $favname | relURL }}">
{{ end -}}
{{ end -}}

View file

@ -23,9 +23,3 @@
<link rel="alternate" hreflang="{{ .Site.LanguageCode | default .Lang }}" href="{{ .Permalink }}">
{{ end -}}
{{ end -}}
<link rel="apple-touch-icon" href="{{ "apple-touch-icon.png" | relURL }}">
{{ if $.Param "realfavicongenerator" -}}
<link rel="icon" type="image/png" sizes="96x96" href="{{ "favicon-96x96.png" | relURL }}">
<link rel="icon" type="image/svg+xml" href="{{ "favicon.svg" | relURL }}">
<link rel="manifest" href="{{ "site.webmanifest" | relURL }}">
{{ end -}}