package web import ( "net/http" "strings" ) // themeCookieName is the cookie projax uses to persist the user's chosen // theme. Read by the layout on render, written by the inline toggle script // in the header nav. Not HttpOnly because the toggle is JS-driven; a // compromise here at worst flips someone's colour scheme. const themeCookieName = "projax_theme" const ( themeDark = "dark" themeLight = "light" ) // themeFromRequest reads the projax_theme cookie. Unknown / missing values // fall back to the default (dark). Whitespace + case are normalised so a // hand-typed cookie still works. func themeFromRequest(r *http.Request) string { if r == nil { return themeDark } c, err := r.Cookie(themeCookieName) if err != nil { return themeDark } v := strings.ToLower(strings.TrimSpace(c.Value)) switch v { case themeLight: return themeLight case themeDark: return themeDark } return themeDark } // themeColorForMeta returns the colour value for the `` // tag. Apple Safari uses this to tint the iOS status bar in the installed PWA. func themeColorForMeta(theme string) string { if theme == themeLight { return "#f0efe8" } return "#161616" }