141 lines
6.0 KiB
Markdown
141 lines
6.0 KiB
Markdown
# yetano-webui-template
|
|
|
|
Shared server-rendered web UI chrome (base layout, navbar, sidebar,
|
|
footer) for the Yetano/Yak/Yamase family of ops-tool admin dashboards.
|
|
This is a real Go module (`teruna.dev/yetano/yetano-webui-template`,
|
|
package `layout`), imported by each dashboard rather than copy-pasted —
|
|
see `layout.go` for the API (`PageHeader`, `NavItem`, `NewRenderer`,
|
|
`StaticHandler`).
|
|
|
|
## Source of truth
|
|
|
|
This repo is the **source of truth** for the shared layout. `yak/yak-webui-template`
|
|
and `yamase/yamase-webui-template` are git-history mirrors of it (each repo's
|
|
root mirrors this repo's root — not a subdirectory — created via `git merge
|
|
--allow-unrelated-histories`, so the histories are related and can be
|
|
re-merged incrementally). Each mirror has exactly one intentional local
|
|
difference: its `go.mod` `module` line, which names that repo's own import
|
|
path instead of this one. Make layout changes *here first*, tag a new
|
|
version, then pull the change into each mirror — never edit the mirrored
|
|
copies directly.
|
|
|
|
### Pulling a change into a mirror
|
|
|
|
From inside `yak-webui-template` or `yamase-webui-template` (each already
|
|
has a `source` remote pointing back here):
|
|
|
|
```sh
|
|
git fetch source main
|
|
git merge source/main
|
|
# resolve the go.mod conflict: keep the mirror's own module line, take
|
|
# everything else from source
|
|
git checkout --ours go.mod # if go.mod conflicted
|
|
git add go.mod
|
|
git commit
|
|
go test ./...
|
|
git push origin main
|
|
```
|
|
|
|
### One-time mirror setup (already done, kept here for reference/re-setup)
|
|
|
|
```sh
|
|
git init -b main
|
|
git remote add source git@teruna.dev:yetano/yetano-webui-template.git
|
|
git fetch source main
|
|
git merge --allow-unrelated-histories -m "Initial mirror of yetano-webui-template" source/main
|
|
go mod edit -module teruna.dev/<org>/<org>-webui-template
|
|
git remote add origin git@teruna.dev:<org>/<org>-webui-template.git
|
|
git push -u origin main
|
|
```
|
|
|
|
## What's shared vs. what stays per-project
|
|
|
|
Shared here: the base HTML skeleton, navbar, sidebar (generic nav-item
|
|
list), footer, and the CSS rules that style exactly those elements
|
|
(`static/style.css` — theme root variables, navbar, `.sidebar .nav-link`
|
|
incl. the `#0b82b8` inactive-link color, footer, flash-banner alerts).
|
|
|
|
Stays in each consuming project: page-specific templates
|
|
(`templates/pages/*.html.tmpl`), page-content CSS (cards, tables, badges,
|
|
forms, buttons, markdown, ...), and anything else specific to that tool.
|
|
|
|
## Theming
|
|
|
|
`static/style.css`'s palette is exposed as `--yw-*` CSS custom properties
|
|
on `:root` (`--yw-bg`, `--yw-text`, `--yw-chrome-bg`, `--yw-accent`,
|
|
`--yw-nav-link`, `--yw-success-*`/`--yw-danger-*`, ...) rather than baked
|
|
directly into each rule — it's a documented, reusable theme, not just an
|
|
implementation detail. This is the *only* theme the module ships: fixed
|
|
dark, no `prefers-color-scheme`, no light mode. Don't add one here on a
|
|
per-project basis (redefining `--yw-*` globally in one consumer would
|
|
silently reskin every future consumer sharing this CSS file); a project
|
|
that genuinely needs a different look — e.g. a light/dark toggle, like
|
|
`yaais` has — should own that itself rather than pushing multi-theme
|
|
complexity into this module, since `yaais` shows that need doesn't
|
|
actually require *this* module either (it's a client-rendered SPA, not a
|
|
server-rendered Go-template dashboard). If a real case for a second theme
|
|
*in* this module shows up later, the `--yw-*` tokens are exactly the
|
|
seam to add one through — redefine them under a `[data-theme="..."]`
|
|
selector the way `yaais`'s own stylesheet does.
|
|
|
|
## Consuming this module
|
|
|
|
```go
|
|
type pageHeader = layout.PageHeader // embed this in your own page data structs
|
|
|
|
r, err := layout.NewRenderer(pagesFS, "templates/pages", pageNames, ".html.tmpl", template.FuncMap{
|
|
"buildInfo": func() string { return version.Get().Compact() },
|
|
})
|
|
...
|
|
mux.Handle("/webui-static/", layout.StaticHandler("/webui-static/"))
|
|
```
|
|
|
|
See `yetano/yasta` for a full worked example (the pilot migration of this
|
|
module).
|
|
|
|
## Migration status
|
|
|
|
Six projects are migrated, on `v0.1.6`.
|
|
|
|
| Project | Meta-repo | Status |
|
|
|---|---|---|
|
|
| `yasta` | yetano | migrated (pilot) |
|
|
| `yasl` | yetano | migrated |
|
|
| `yaiam` | yetano | migrated |
|
|
| `yakwui` | yak | migrated |
|
|
| `yamase-web` | yamase | migrated |
|
|
| `yamocir` | yetano | migrated |
|
|
|
|
`yaais` was evaluated too and deliberately NOT migrated: it's a
|
|
client-rendered SPA (static `index.html` + vanilla JS), not a
|
|
server-rendered Go-template dashboard, so this module's actual
|
|
deliverable (Go templates) doesn't apply. It adopted the same dark
|
|
palette independently in its own stylesheet instead, plus its own
|
|
light/dark toggle — see its `internal/yaais/static/style.css`.
|
|
|
|
## Versioning note
|
|
|
|
Use `v0.1.5` or later. `v0.1.3` and `v0.1.4` were force-moved to
|
|
different content after being tagged (a mistake, made while resolving a
|
|
concurrent-edit conflict during the initial rollout) and can produce a
|
|
`go.sum` checksum mismatch for anyone who fetched them beforehand. Don't
|
|
force-move an existing tag again for any future change — always cut a
|
|
new one, even for a one-line fix.
|
|
|
|
## PageHeader fields (current as of v0.1.5)
|
|
|
|
`Title`, `AppName` (lowercase product name for `<title>`/footer — not
|
|
`Name`, which collides with a domain type's own `Name` field once
|
|
embedded in the same struct, as yakwui's viewmodel types do), `Lang`
|
|
(`<html lang>`, defaults to `"en"`), `Brand`, `BrandInitial`, `Subtitle`,
|
|
`BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`,
|
|
`LogoutPath` (a plain GET link — for a POST-form logout or any other
|
|
markup mismatch, render it yourself into `NavbarRightExtra` instead and
|
|
leave `Username`/`LogoutPath` unset), `NavbarBeforeBrand` (before the
|
|
brand link, e.g. a mobile sidebar-toggle button),
|
|
`NavbarLeftExtra`/`NavbarRightExtra` (the navbar's two groups),
|
|
`ExtraHeadHTML`/`ExtraBodyHTML`, and `BodyAttrs`/`SidebarAttrs` —
|
|
`template.HTMLAttr`, not `template.HTML` — raw extra attributes on
|
|
`<body>` and the sidebar `<nav>` for a consumer's own client-side
|
|
framework state (e.g. yakwui's Alpine.js collapsible sidebar).
|