// Package layout provides the shared server-rendered web UI chrome (base // layout, navbar, sidebar, footer) used by every Yetano/Yak/Yamase // ops-tool admin dashboard: yasta, yasl, yaiam, yakwui, yamase-web, and // yamocir. // // Consumers embed PageHeader in their own per-page data struct and use // NewRenderer to parse the shared layout templates together with their // own page-specific templates. Page-content styling (cards, tables, // badges, forms, ...) stays each project's own concern; only the chrome // that base/navbar/sidebar/footer actually render is shared here. package layout import ( "embed" "fmt" "html/template" "io" "io/fs" "net/http" ) //go:embed templates/layout var templateFS embed.FS //go:embed static var staticFS embed.FS // LayoutGlob is the glob NewRenderer uses to pull in the shared // base/navbar/sidebar/footer templates. const LayoutGlob = "templates/layout/*.tmpl" // Values for PageHeader.Theme, the color mode; see static/style.css. const ( ThemeDark = "dark" ThemeLight = "light" ThemeSystem = "system" ) // NavItem is one sidebar entry. type NavItem struct { ID string // matches PageHeader.ActiveNav to mark this item active Label string Href string // BasePath-relative, e.g. "/tasks" // Group, when set, puts a small heading above the first item of a // run of items with the same Group ("Account", "Downloads", ...). Group string // Icon names one of NavIcons ("dashboard", "settings", ...); unknown // names render nothing. Only StyleModern shows icons, so setting it // leaves the classic look unchanged. Icon string } // SidebarEntry is one NavItem as the sidebar template renders it. type SidebarEntry struct { NavItem Active bool GroupHead string // the group heading to render before this item, if any IconSVG template.HTML // NavIcons[Icon] } // SidebarEntries resolves NavItems for the sidebar template: active // state, group headings (once per run of equal Group values) and icons. func (h PageHeader) SidebarEntries() []SidebarEntry { out := make([]SidebarEntry, len(h.NavItems)) prev := "" for i, n := range h.NavItems { e := SidebarEntry{NavItem: n, Active: n.ID == h.ActiveNav, IconSVG: navIcon(n.Icon)} if n.Group != "" && n.Group != prev { e.GroupHead = n.Group } prev = n.Group out[i] = e } return out } // PageHeader holds the fields every page's own data struct should embed // so the shared base/navbar/sidebar/footer templates can render // regardless of which project or page is being rendered. Zero-valued // fields simply render nothing (e.g. Username == "" hides the // username/logout group). type PageHeader struct { Title string // AppName is the lowercase product name, e.g. "yasta", used in //