repos
/ orchard main

orchard

mirror

Every site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.

blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics

1.6 KB · 41 lines · Go Raw History
 1package main
 2
 3import (
 4	"crypto/sha256"
 5	"encoding/hex"
 6	"net/http"
 7	"strings"
 8)
 9
10// An inline SVG rather than a file, since it is two elements and a build step
11// for it would generate more than it saves.
12//
13// The mark from the rail, set solid in the page's phosphor amber on the warm
14// near black it sits on, so the tab and the wordmark are the same shape. Isaac
15// picked it off a sheet of ten after a sparkline and a cassette were both
16// rejected, and the reason those failed is worth keeping: a favicon is a 16
17// pixel object and all three were being judged at 128.
18//
19// The triangle is drawn nearly to the edges on purpose. Smaller versions of it
20// left a dark margin that swallowed the shape at tab size.
21const faviconSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">` +
22	`<rect width="32" height="32" rx="7" fill="#0d0b09"/>` +
23	`<path d="M5.5 26.5V5.5h21z" fill="#ffb000"/>` +
24	`</svg>`
25
26// faviconVersion is a short content hash, and the page links the icon with it
27// on the query string. Cloudflare held the previous icon for its full day after
28// it changed, which is correct of it and useless to anybody looking at the tab,
29// and a browser caches a favicon harder still. Versioning the URL is what makes
30// a change to the constant above actually arrive.
31var faviconVersion = func() string {
32	sum := sha256.Sum256([]byte(faviconSVG))
33	return hex.EncodeToString(sum[:4])
34}()
35
36func favicon(w http.ResponseWriter, r *http.Request) {
37	w.Header().Set("Content-Type", "image/svg+xml")
38	w.Header().Set("Cache-Control", "public, max-age=86400")
39	_, _ = strings.NewReader(faviconSVG).WriteTo(w)
40}