Skip to content

Commit

Permalink
Move favicons to seperate partial so it can use partialCached. Remove…
Browse files Browse the repository at this point in the history
… realfavicongenerator setting and autodetect favicon files instead.
  • Loading branch information
frjo committed Nov 25, 2024
1 parent 91950cb commit 2bea241
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ params:
plausibleTrackerURL: "" # Plausible url, schemaless and no slash on end. Optional, defaults to "plausible.io/…"
poweredby: true # Show powered by hugo in footer
privacyPolicyUrl: "" # If set will add link to cookie consent form.
realfavicongenerator: # If full set of favicons, site manifest etc. exists, default false.
relatedposts: true # Show related posts under a "See also" section, default false.
sassTranspiler: "dartsass"# The Sass transpiler to use, default "libsass".
searchLimit: 20 # Max number of search hits, default 20.
Expand Down Expand Up @@ -360,9 +359,9 @@ Place your logo at `static/images/logo.png`. If you don't provide a logo, then t

### Favicons

Upload your image to [RealFaviconGenerator](https://realfavicongenerator.net/) then copy-paste the generated favicon files under `static`.
Upload your image to [RealFaviconGenerator](https://realfavicongenerator.net/) then copy the generated favicon files in to the `static` directory. (Do not place them in a sub directory.)

Then set the "realfavicongenerator" param to true to add the needed meta tags. Also good to set the "themeColor" param to correct colour.
The theme will autodetect them and add the needed code.


### Head and footer partials
Expand Down
1 change: 1 addition & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down
17 changes: 17 additions & 0 deletions layouts/partials/favicons.html
Original file line number Diff line number Diff line change
@@ -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 -}}
6 changes: 0 additions & 6 deletions layouts/partials/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

0 comments on commit 2bea241

Please sign in to comment.