feat: configurable favicon supporting SVG, PNG, and JPG Add meta.favicon config option with auto-detected MIME type from file extension. Defaults to static/favicon.svg. Users can drop any PNG, JPG, or SVG into static/ and set meta.favicon in config.yaml without touching templates.
Maxwell Jensen maxwelljensen@posteo.net
Tue, 12 May 2026 18:30:20 +0200
6 files changed,
29 insertions(+),
2 deletions(-)
M
configs/config_example.yaml
→
configs/config_example.yaml
@@ -11,8 +11,10 @@ dirs:
templates: ./templates static: ./static meta: + favicon: favicon.svg title: legit description: Oui, il est le git! + syntaxHighlight: monokailight server: name: example.org host: 0.0.0.0
M
internal/config/config.go
→
internal/config/config.go
@@ -3,6 +3,7 @@
import ( "fmt" "path/filepath" + "strings" "github.com/spf13/viper" )@@ -23,6 +24,10 @@ Meta struct {
Title string `mapstructure:"title"` Description string `mapstructure:"description"` SyntaxHighlight string `mapstructure:"syntaxHighlight"` + Favicon string `mapstructure:"favicon"` + + FaviconHref string + FaviconType string } `mapstructure:"meta"` Server struct { Name string `mapstructure:"name,omitempty"`@@ -55,6 +60,22 @@ return nil, err
} if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil { return nil, err + } + + // Default favicon and compute MIME type + if c.Meta.Favicon == "" { + c.Meta.Favicon = "favicon.svg" + } + c.Meta.FaviconHref = "/static/" + c.Meta.Favicon + switch strings.ToLower(filepath.Ext(c.Meta.Favicon)) { + case ".svg": + c.Meta.FaviconType = "image/svg+xml" + case ".png": + c.Meta.FaviconType = "image/png" + case ".jpg", ".jpeg": + c.Meta.FaviconType = "image/jpeg" + default: + c.Meta.FaviconType = "image/x-icon" } return c, nil
A
static/favicon.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"> + <rect width="32" height="32" rx="4" fill="#c1272d"/> + <text x="16" y="22" text-anchor="middle" font-family="Inter,-apple-system,BlinkMacSystemFont,sans-serif" font-size="17" font-weight="800" fill="#fff">le</text> +</svg>
M
templates/head.html
→
templates/head.html
@@ -3,7 +3,7 @@ <head>
<meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="/static/style.css" type="text/css"> - <link rel="icon" type="image/png" size="32x32" href="/static/legit.png"> + <link rel="icon" type="{{ .meta.FaviconType }}" href="{{ .meta.FaviconHref }}"> {{ if .parent }} <title>{{ .meta.Title }} — {{ .name }} ({{ .ref }}): {{ .parent }}/</title>