all repos — legit @ 962e84f92cc6d50e624b666bf2aefa21d8656e6f

Unnamed repository; edit this file 'description' to name the repository.

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
commit

962e84f92cc6d50e624b666bf2aefa21d8656e6f

parent

889bf52d08fd7b38160a6435d6f0409acc6cba89

M README.mdREADME.md

@@ -64,7 +64,6 @@ - README.md

- README mainBranch: - master - - main ignore: - foo unlisted:

@@ -73,6 +72,7 @@ dirs:

templates: ./templates static: ./static meta: + favicon: favicon.svg title: git good description: come get your free software syntaxHighlight: monokailight
M configs/config_example.yamlconfigs/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.gointernal/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.htmltemplates/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 }} &mdash; {{ .name }} ({{ .ref }}): {{ .parent }}/</title>