Compare commits

...
2 Commits
Author SHA1 Message Date
terminarandClaude Opus 5.5 d0e49b2365 Navbar logout as a POST form instead of a GET link
A GET logout can be triggered from any foreign page (img/link) and by
link prefetchers. LogoutPath now renders <form method="post"> with a
submit button styled like the former link; consumers register the route
as POST only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 15:27:10 +01:00
terminarandClaude Opus 5.5 b6a6298353 README: the yak/yamase mirrors are gone, consumers import this module directly
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 15:03:33 +02:00
4 changed files with 39 additions and 44 deletions

No files matched your search

+15 -42
View File
@@ -9,44 +9,13 @@ see `layout.go` for the API (`PageHeader`, `NavItem`, `NewRenderer`,
## Source of truth ## Source of truth
This repo is the **source of truth** for the shared layout. `yak/yak-webui-template` This repo is the **single source of truth** for the shared layout. Every
and `yamase/yamase-webui-template` are git-history mirrors of it (each repo's consumer -- in `yetano`, `yak` (`yakwui`) and `yamase` (`yamase-web`) --
root mirrors this repo's root — not a subdirectory — created via `git merge imports `teruna.dev/yetano/yetano-webui-template` directly: make layout
--allow-unrelated-histories`, so the histories are related and can be changes here, tag a new version, then bump the consumers. The former
re-merged incrementally). Each mirror has exactly one intentional local git-history mirrors `yak/yak-webui-template` and
difference: its `go.mod` `module` line, which names that repo's own import `yamase/yamase-webui-template` were removed and their repositories
path instead of this one. Make layout changes *here first*, tag a new archived on 2026-10-23 (nothing imported them).
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 ## What's shared vs. what stays per-project
@@ -147,7 +116,7 @@ concurrent-edit conflict during the initial rollout) and can produce a
force-move an existing tag again for any future change — always cut a force-move an existing tag again for any future change — always cut a
new one, even for a one-line fix. new one, even for a one-line fix.
## PageHeader fields (current as of v0.1.9) ## PageHeader fields (current as of v0.1.10)
`Title`, `AppName` (lowercase product name for `<title>`/footer — not `Title`, `AppName` (lowercase product name for `<title>`/footer — not
`Name`, which collides with a domain type's own `Name` field once `Name`, which collides with a domain type's own `Name` field once
@@ -155,9 +124,13 @@ embedded in the same struct, as yakwui's viewmodel types do), `Lang`
(`<html lang>`, defaults to `"en"`), `Theme` (`<html data-theme>`, see (`<html lang>`, defaults to `"en"`), `Theme` (`<html data-theme>`, see
Theming), `Brand`, `BrandInitial`, `Subtitle`, Theming), `Brand`, `BrandInitial`, `Subtitle`,
`BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`, `BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`,
`LogoutPath` (a plain GET link — for a POST-form logout or any other `LogoutPath` (since v0.1.10 a `<form method="post">` with a submit
markup mismatch, render it yourself into `NavbarRightExtra` instead and button styled like the former link, never a GET link: a logout reachable
leave `Username`/`LogoutPath` unset), `NavbarBeforeBrand` (before the by GET can be triggered from any foreign page via an `<img>`/link and by
link prefetchers; the consumer registers the route as `POST` only and
answers `GET` with 405 + `Allow: POST`. If the form needs a hidden CSRF
field or other markup, render it yourself into `NavbarRightExtra` and
leave `LogoutPath` unset), `NavbarBeforeBrand` (before the
brand link, e.g. a mobile sidebar-toggle button), brand link, e.g. a mobile sidebar-toggle button),
`NavbarLeftExtra`/`NavbarRightExtra` (the navbar's two groups), `NavbarLeftExtra`/`NavbarRightExtra` (the navbar's two groups),
`ExtraHeadHTML`/`ExtraBodyHTML`, and `BodyAttrs`/`SidebarAttrs` — `ExtraHeadHTML`/`ExtraBodyHTML`, and `BodyAttrs`/`SidebarAttrs` —
+1 -1
View File
@@ -75,7 +75,7 @@ type PageHeader struct {
Flash string Flash string
FlashKind string // "ok" or "error"; meaningless if Flash == "" FlashKind string // "ok" or "error"; meaningless if Flash == ""
Username string Username string
LogoutPath string // BasePath-relative, e.g. "/logout"; "" hides the logout link LogoutPath string // BasePath-relative, e.g. "/logout"; rendered as a POST form (never a GET link); "" hides it
NavbarBeforeBrand template.HTML // extra markup rendered before the brand link, e.g. a mobile sidebar toggle NavbarBeforeBrand template.HTML // extra markup rendered before the brand link, e.g. a mobile sidebar toggle
NavbarLeftExtra template.HTML // extra markup rendered after Subtitle in the navbar's left group NavbarLeftExtra template.HTML // extra markup rendered after Subtitle in the navbar's left group
NavbarRightExtra template.HTML // extra markup rendered after Username/Logout in the navbar's right group NavbarRightExtra template.HTML // extra markup rendered after Username/Logout in the navbar's right group
+22
View File
@@ -178,3 +178,25 @@ func TestThemeBlocksInSync(t *testing.T) {
t.Errorf("light and prefers-color-scheme: light blocks differ:\nlight: %v\nsystem: %v", light, system) t.Errorf("light and prefers-color-scheme: light blocks differ:\nlight: %v\nsystem: %v", light, system)
} }
} }
// TestLogoutIsPostForm pins the navbar's logout control to a POST form:
// a GET link would let any foreign page (an <img>, a link prefetcher)
// log the user out.
func TestLogoutIsPostForm(t *testing.T) {
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
if err != nil {
t.Fatalf("NewRenderer: %v", err)
}
var buf bytes.Buffer
data := PageHeader{Title: "Dashboard", BasePath: "/ui", Username: "alice", LogoutPath: "/logout"}
if err := r.Page(&buf, "dashboard", data); err != nil {
t.Fatalf("Page: %v", err)
}
out := buf.String()
if !strings.Contains(out, `<form method="post" action="/ui/logout"`) {
t.Errorf("logout is not a POST form\n---\n%s", out)
}
if strings.Contains(out, `href="/ui/logout"`) {
t.Errorf("logout still rendered as a GET link\n---\n%s", out)
}
}
+1 -1
View File
@@ -9,7 +9,7 @@
</div> </div>
<div class="d-flex align-items-center gap-2"> <div class="d-flex align-items-center gap-2">
{{if .Username}}<span class="navbar-subtitle">{{.Username}}</span>{{end}} {{if .Username}}<span class="navbar-subtitle">{{.Username}}</span>{{end}}
{{if .LogoutPath}}<a href="{{.BasePath}}{{.LogoutPath}}" class="btn btn-outline-secondary btn-sm">Logout</a>{{end}} {{if .LogoutPath}}<form method="post" action="{{.BasePath}}{{.LogoutPath}}" class="d-inline m-0"><button type="submit" class="btn btn-outline-secondary btn-sm">Logout</button></form>{{end}}
{{.NavbarRightExtra}} {{.NavbarRightExtra}}
</div> </div>
</div> </div>