Commit dd6e7c8f authored by Laura Kalbag's avatar Laura Kalbag
Browse files

Auto-generate icon.svg favicon using chosen theme colours

parent cab4b4a6
<?xml version="1.0" encoding="UTF-8"?>
{{- /* a basic circle icon filled with the corresponding colours to the chosen theme colour */ -}}
{{- /* get the theme colour */ -}}
{{ $colourTheme := partial "get-param/colour-theme.html" . }}
{{- /* get the theme colour’s corresponding data file so we can use its values */ -}}
{{ $colourFile := index site.Data.colourThemes.themes $colourTheme }}
{{- /* get the theme colours’s theme lightmode colour from the colour file */ -}}
{{ $themeLightmode := $colourFile.themeLightmode }}
{{- /* get the theme colours’s theme darkmode colour from the colour file */ -}}
{{ $themeDarkmode := $colourFile.themeDarkmode }}
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>
@media (prefers-color-scheme: dark) {
#disc { fill: {{ $themeDarkmode }}; }
}
</style>
<title>{{ .Site.Title }}</title>
<g id="default" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g fill="{{ $themeLightmode }}" id="disc">
<circle cx="16" cy="16" r="16"></circle>
</g>
</g>
</svg>
\ No newline at end of file
......@@ -29,6 +29,18 @@ https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-mo
{{- /* the theme’s default favicon.ico is greyscale, fancier browsers that support favicon.svg will get a theme-colour/darkmode/lightmode corresponding version generated */ -}}
<link rel='icon' href='favicon.ico'>
{{- /* icon.svg specifying light and dark mode colours */ -}}
{{- /* if an icon.svg already exists in .hugo/static, use that */ -}}
{{- if (fileExists "static/icon.svg") }}
<link rel='icon' type='image/svg+xml' href='/icon.svg'>
{{- else }}
{{- /* otherwise generate a colour-theme corresponding (including lightmode/darkmode) version of the icon.svg kept in starter-theme/assets/favicons */ -}}
{{- $iconSvg := resources.Get "favicons/icon.svg" }}
{{- $iconSvgFile := $iconSvg | resources.ExecuteAsTemplate "icon.svg" . }}
<link rel='icon' type='image/svg+xml' href='{{ $iconSvgFile.RelPermalink }}'>
{{- end }}
{{- /* pull in web manifest file */ -}}
{{- $webmanifest := resources.Get "favicons/site.webmanifest" }}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment