Skip to content

Commit

Permalink
refactor!: move favicon site param to page param (#41)
Browse files Browse the repository at this point in the history
This commit moves and renames
`.Site.params.faviconEmojiTemplate` to
`.Page.params.faviconText`. This both clarifies
that the parameter accepts any text - not
necessarily an emoji, as well as furthering a
wider effort to make this page fully configurable
from one location.

* refactor: move favicon template to head partial

We move the favicon svg template to the head
partial, since it will never be used anywhere
else.

* fix: bust favicon cache during development

While using `hugo server`, the first generated
favicon would cached and used for the duration. We
now name the generated resource with its md5 hash
to prevent this.
  • Loading branch information
cjshearer authored Feb 12, 2024
1 parent 03d705b commit cd1d6f6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
5 changes: 0 additions & 5 deletions assets/images/faviconEmojiTemplate.svg

This file was deleted.

1 change: 1 addition & 0 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dateformat:
short: Jan. 2006
long: January 2006
title: Resume
faviconText: 💼
skills:
- languages:
- TypeScript
Expand Down
2 changes: 0 additions & 2 deletions hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,3 @@ outputFormats:
mediaType: text/plain
baseName: index
isPlainText: true
Params:
faviconEmoji: 💼
12 changes: 10 additions & 2 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
<link rel="preload" href="{{ $googleFontURL }}" as="style" />
<link rel="stylesheet" href="{{ $googleFontURL }}" />
<link rel="canonical" href="{{ .Permalink }}" />
{{ if .Site.Params.faviconEmoji }}
{{ $favicon := resources.Get "images/faviconEmojiTemplate.svg" | resources.Minify | resources.ExecuteAsTemplate "images/favicon.svg" . }}
{{ with .Page.Params.faviconText }}
{{ $faviconString := print
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">`
`<text y="0.9em" font-size="80">` . `</text>
</svg>`
}}
{{ $favicon := $faviconString
| resources.FromString (print "images/" (md5 $faviconString) ".svg")
| resources.Minify
}}
<link
rel="icon"
href="data:{{ $favicon.MediaType.Type }};base64,{{ $favicon.Content | base64Encode }}"
Expand Down

0 comments on commit cd1d6f6

Please sign in to comment.